-->
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.  [ 2 posts ] 
Author Message
 Post subject: @SecondaryTable and Inheritance
PostPosted: Wed Mar 30, 2011 8:35 am 
Newbie

Joined: Mon Mar 28, 2005 7:40 am
Posts: 5
Hi all!
I have 3 classes:

Code:
@Entity
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn
public class User {
    @Id
     private Long id;
......
}

@Entity
@SecondaryTable(name="external_user")
@Table(appliesTo="external_user",optional=false)
public class ExternalUser extends User {
     @Column(table="external_user")
     private String name;
......
}

@Entity
@SecondaryTable(name="external_user")
public class Guest extends ExternalUser {
     @Column(table="external_user")
     private String enabled;
......
}


If I insert a new Guest setting only the fields of User class the row is created in the USER and EXTERNAL_USER tables.
But when I set the "enabled" field in Gust class, i get a PK violated constraint error.
In the hibernate log a get this:
Quote:
insert into user(id) values(?)
insert into external_user(id) values(?)
insert into external_user(id,enabled) values(?,?)


Why is inserted twice in the secondary table?
I add the @Table(appliesTo="external_user",optional=false) in the Guest class and does not work.

I need this class hierarchy
Any help?
Thanks!


Top
 Profile  
 
 Post subject: Re: @SecondaryTable and Inheritance
PostPosted: Wed May 25, 2011 6:21 am 
Pro
Pro

Joined: Wed Nov 05, 2003 7:22 pm
Posts: 211
I have the same problem. Did you resolve this?


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

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.