Hi,
According to Hibernate Docs, in can mix various inheritance strategies using SecondaryTable.
Unfortunately, I get Unique Constaints Violation Exception because Hibernate performs two insert in the table SubClass1 by creating the entity SubClass2 .
Does anyone have any idea can i solve this problem ? or there is other solution to mix inheritance strategies to solve different?
thanks
SupperClass (Eigene Tabelle= SupperClass)
.........|------------------SubClass1 (Eigene Tabelle= SubClass1)
....................................................|------------------SubClass2 (Keine Eigene Tabelle ( SubClass1))
.......................................................................................... |------------------SubClass3 (Keine Eigene Tabelle ( SubClass1))
Code:
@Entity
@Table(name = "SupperClass")
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name="DC",discriminatorType=DiscriminatorType.INTEGER)
@DiscriminatorValue(value = "0")
class SupperClass{
}
-------------------------
Code:
@Entity
@DiscriminatorValue(value = "1")
@SecondaryTable(name = "SubClass1",pkJoinColumns = {
@PrimaryKeyJoinColumn(name = "ID", referencedColumnName = "ID")})
public class SubClass1 extends SupperClass {
@Column(table = "SubClass1")
private String attribut1;
}
-------------------------
Code:
@Entity
@DiscriminatorValue(value = "2")
@SecondaryTable(name = "SubClass1",pkJoinColumns = {
@PrimaryKeyJoinColumn(name = "ID", referencedColumnName = "ID")})
public class SubClass2 extends SubClass1{
@Column(table = "SubClass1")
private String attribut2;
}
-------------------------
Code:
@Entity
@DiscriminatorValue(value = "3")
@SecondaryTable(name = "SubClass1",pkJoinColumns = {
@PrimaryKeyJoinColumn(name = "ID", referencedColumnName = "ID")})
public class SubClass3 extends SubClass2{
@Column(table = "SubClass1")
private String attribut3;
}