-->
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.  [ 4 posts ] 
Author Message
 Post subject: How save a subclass with parent created
PostPosted: Mon Feb 13, 2006 4:58 pm 
Newbie

Joined: Fri Apr 01, 2005 10:38 am
Posts: 3
Location: Chile
Hibernate version:2.1.8

Hello
I want to save class B with class A like parent, object A was created before.
I have tried to save class B but, when you try this, is created A with B.

do you have how to do this?

Thank you

Andreikov


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 13, 2006 6:38 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
If you're using subclasses, an instance of a subclass (class B) is an instance of the superclass too (class A). If you're expecting your object to have two separate classes, A and B, where B is subclassed from A, then you aren't fully understanding object orientation or polymorphism. It is possible that you shouldn't be subclassing, you should have distinct classes with a relational association (a many-to-one or whatever).


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 14, 2006 9:59 am 
Newbie

Joined: Fri Apr 01, 2005 10:38 am
Posts: 3
Location: Chile
We take the following case:
I have the class User with a lot of users registered, after (1 year after) I want to classify the users (the next and old users) like admin and common, then I need to create two subclasses from class User called AdminUser and CommonUser adding another attributes.
Then, I would like to create AdminUser for an old User, that is the questions, and I have problem to this operation

Best regards

Andreikov


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 14, 2006 5:16 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
Create an (in-memory) AdminUser with the same fields as the existing User (including the PK field), then save the AdminUser. Make sure you Session.evict() the User before saving the AdminUser, so that you don't have two cached objects referring to the same DB row.

From then on, retrieving that User will return an AdminUser.


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