-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: mix various inheritance strategies
PostPosted: Wed Nov 03, 2010 8:08 am 
Newbie

Joined: Tue Nov 02, 2010 9:26 am
Posts: 2
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;
}


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.