我在JPA和HIBERNATE中使用继承,所以我有这些实体:
@Entity
@Inheritance( strategy = InheritanceType.SINGLE_TABLE )
@DiscriminatorColumn( name = "entityType",
discriminatorType = DiscriminatorType.STRING )
public abstract class A implements Serializable
{
@Id
private String id;
@ManyToOne
@JoinColumn(name = "Z_ID", nullable = false)
private Z z;
// other mapped properties...
}
@Entity
@DiscriminatorValue("BB")
public class BB extends A
{
@Basic( optional = false)
@Column( table = "BB" )
private String property1;
// other mapped properties and associations...
}
@Entity
@DiscriminatorValue("CC")
public class CC extends A
{
@ManyToOne( optional = false)
@JoinColumn( table = "CC" )
private SomeEntity association1;
// other mapped properties and associations...
}
public class Z implements Serializable
{
@Id
private String id;
@OneToMany(fetch = FetchType.LAZY, mappedBy = "z", cascade= CascadeType.ALL, orphanRemoval=true)
private Set<A> as;
// other mapped properties...
}
我知道我可以在实体Z中添加两个属性bb和cc,但是从A继承了许多其他实体,所以我问是否只有一个属性z有解决方案。 上面的实现给了我一个例外:
org.hibernate.exception.GenericJDBCException: Could not read entity state from ResultSet