JPA映射接口为EclipseLink中的@Entity [英] JPA mapping Interface as @Entity in EclipseLink
问题描述
我必须将接口映射为实体,以便在集合中使用不同的实现。
I have to map the interface as entity to use different implementations in collections.
@Entity
@Table(name = "OPTION")
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = "TYPE", discriminatorType = DiscriminatorType.STRING)
public interface FilterOption {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
public Long getId();
public void setId(Long id);
public Object getValue();
...
}
我收到错误:
内部异常:异常[EclipseLink-7161](Eclipse持久性
服务 - 2.2.0.v20110202-r8913):
org.eclipse.persistence.exceptions.ValidationException异常
描述:实体类[class
FilterOption]没有指定主
键。它应该定义@Id,@ EmbeddedId或
@IdClass。
Internal Exception: Exception [EclipseLink-7161] (Eclipse Persistence Services - 2.2.0.v20110202-r8913): org.eclipse.persistence.exceptions.ValidationException Exception Description: Entity class [class FilterOption] has no primary key specified. It should define either an @Id, @EmbeddedId or an @IdClass.
正如你可以看到@Id是声明。如何解决此问题?
As you can see the @Id is declared. How can I fix this problem?
推荐答案
您无法使用带eclipselink的注释将实体映射到接口,显然。
you can't map entities to interfaces using annotations with eclipselink, apparently.
实际上,您无法将实体映射到接口处全部使用 jpa或hibernate 。
In fact, you can't map an entity to an interface at all using jpa or hibernate.
这篇关于JPA映射接口为EclipseLink中的@Entity的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!