-->
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: inheritance mapping and type changing between subclasses
PostPosted: Tue Jul 31, 2007 3:13 am 
Newbie

Joined: Tue Jul 31, 2007 2:16 am
Posts: 4
There two types of user in my domain model: OrdinaryUser and AdminUser. I use the "TABLE Per Hierarchy" stategy to mapping these two types of user as subclasses of User with a discriminator column called "user_type".

And now I want to promote an ordinary user to an admin user without changing his id (which is generated by the sequence generator.), and name.

How can I do that in Hibernate?

I have searched this topic in Google for a long time and can't find an answer.

Thanks very much.


Top
 Profile  
 
 Post subject: change an object's discriminator value
PostPosted: Tue Jul 31, 2007 4:47 am 
Newbie

Joined: Tue Jul 31, 2007 2:16 am
Posts: 4
Whether an object's discriminator value can be changed after it has been saved into database?[/code]


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 31, 2007 9:49 am 
Newbie

Joined: Sun Apr 09, 2006 8:38 am
Posts: 14
How are you planning to do the "promotion" in java?
if you have 2 seperate classes for the user types -
you're going to have to :

//write a constructor that does the data copying and instantiation
//for the AdvancedUser class
AdvancedUser au = new AvancedUser(simpleUser);
Hibernate.delete(simpleUser);

//exit session here !!! very important!!!

au.setId(simpleUser.getId())
Hibernate.save(au);
//preferably force flush() here too...


Top
 Profile  
 
 Post subject: It does not work.
PostPosted: Tue Jul 31, 2007 10:58 am 
Newbie

Joined: Tue Jul 31, 2007 2:16 am
Posts: 4
Thank you for your reply.

I have try it and it does not work. The exception is as follows:

2007-07-31 22:57:17,546 ERROR [org.hibernate.jdbc.AbstractBatcher] - Exception executing batch:
org.hibernate.StaleStateException: Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 31, 2007 11:26 am 
Newbie

Joined: Sun Apr 09, 2006 8:38 am
Posts: 14
intuition - you didn't exit the session before trying to create the AdvancedUser.

please post full stack trace.

(and don't forget to rate...:-)


Top
 Profile  
 
 Post subject: It still does not work
PostPosted: Tue Jul 31, 2007 11:45 am 
Newbie

Joined: Tue Jul 31, 2007 2:16 am
Posts: 4
since I use the sequence ID generator and when I save an object with explicitly setting id, it would throw exception:

org.hibernate.StaleStateException: Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1

Assafp wrote:
intuition - you didn't exit the session before trying to create the AdvancedUser.

please post full stack trace.

(and don't forget to rate...:-)


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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.