I'm using inheritence with JPA and HIBERNATE so i have these entities :
@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...
}
I know that i can add two attributes bb and cc in the entity Z but have many other entities inheritence from A so i ask if there any solution to only one attribute z. The implementation above gave me an exception :
org.hibernate.exception.GenericJDBCException: Could not read entity state from ResultSet