-->
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.  [ 5 posts ] 
Author Message
 Post subject: sequence generator on save
PostPosted: Tue Dec 09, 2008 12:47 am 
Newbie

Joined: Fri Nov 09, 2007 8:52 pm
Posts: 2
When does hibernate use unsaved-value=0 for ID. If the id generation method is sequence generator and ID is greater than zero, does hibernate generate the sequence number on calling Save() method?


Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 09, 2008 3:48 am 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
As far as I know the unsaved-value is only used by the Session.saveOrUpdate() method to determine if if should delegate to Session.save() or Session.update().


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 09, 2008 4:27 am 
Newbie

Joined: Fri Nov 09, 2007 8:52 pm
Posts: 2
Thanks nordborg for your reply.

My issue is, mapping has sequence generator for the identifier. There is one scenario where, entity already has the identifier assigned and do not want hibernate regenerate the identifier on save(). But, hibernate overrides my identifier. How can I handle this scenario?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 09, 2008 4:35 am 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
I don't think any of the built-in Hibernate generators can do it. You may have to implement your own identifier generator.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 09, 2008 2:38 pm 
Beginner
Beginner

Joined: Thu Oct 02, 2008 10:15 am
Posts: 21
I think the key here is use saveOrUpdate() method. This method will assign a "key" if not found for the object and do a save. If a key is already assigned it will update that entity.


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