-->
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.  [ 6 posts ] 
Author Message
 Post subject: 1 table, 2 beans
PostPosted: Fri Nov 20, 2009 6:56 pm 
Newbie

Joined: Wed Apr 08, 2009 1:11 pm
Posts: 19
Hi,

I have an Author and a User bean that are identical in fields, that share a subclass. I want to map them to the same table.

My ideal approach is that in each mapping file for the respective bean, I can enforce a particular discriminator value for a character property. Is this possible?

Otherwise, in the constructor for each bean, can I call the setter for the 'discriminator' with the correct value.
And make this setter protected.

Andy


Top
 Profile  
 
 Post subject: Re: 1 table, 2 beans
PostPosted: Mon Nov 23, 2009 5:41 am 
Expert
Expert

Joined: Thu Jan 08, 2009 6:16 am
Posts: 661
Location: Germany
andynuss wrote:
I have an Author and a User bean that are identical in fields, that share a subclass.
Andy

How can two classes share a subclass?? Multi-inheritance is not possible in java.

_________________
-----------------
Need advanced help? http://www.viada.eu


Top
 Profile  
 
 Post subject: Re: 1 table, 2 beans
PostPosted: Mon Nov 23, 2009 11:08 am 
Newbie

Joined: Wed Apr 08, 2009 1:11 pm
Posts: 19
My mistake. I meant base class Entity.


Top
 Profile  
 
 Post subject: Re: 1 table, 2 beans
PostPosted: Mon Nov 23, 2009 11:17 am 
Expert
Expert

Joined: Thu Jan 08, 2009 6:16 am
Posts: 661
Location: Germany
Do you mean this?

_________________
-----------------
Need advanced help? http://www.viada.eu


Top
 Profile  
 
 Post subject: Re: 1 table, 2 beans
PostPosted: Mon Nov 23, 2009 2:34 pm 
Newbie

Joined: Wed Apr 08, 2009 1:11 pm
Posts: 19
Well, what I've done is a base class Entity that defines all the getters and setters. One of them is for the isAuthor property. Then I create two subclasses, User and Author, which, in their constructor call setIsAuthor(false/true) according to which it is. Then I have two mapping files, one for Author and one for User, which map the same set of properties (all in Entity) to 2 completely different tables. Author and User only supply a specialized constructor, otherwise, inherit the base class properties. What I'm thinking is that I shouldn't even map isAuthor at all, and just return true and false, making it an unmapped property.


Top
 Profile  
 
 Post subject: Re: 1 table, 2 beans
PostPosted: Tue Nov 24, 2009 4:17 am 
Expert
Expert

Joined: Thu Jan 08, 2009 6:16 am
Posts: 661
Location: Germany
Yes, thats a possible solution. You should also think about using @MappedSuperclass instead of making your base-class to an entity, because you map the superclass properties to your child-tables.

_________________
-----------------
Need advanced help? http://www.viada.eu


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 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.