Hallo,
Laut Hibernate Docs kann man anhand SecondaryTable die verschiedenen Vererbungsstategien mischen.
Leider bekomme ich Unique Constaints Violation Exception,da Hibernate bei Anlegen zum Beispiel ein SubClass2 zwei Insert in der Tabelle SubClass1 ausführt.
Hat jemand eine Idee,woran es liegen kann? und wie kann man das verhindern? Oder wie man das mischen Vererbungsstategien anderes lösen kann?
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;
}