-->
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: Hibernate Support for Upsert/Merge?
PostPosted: Fri Mar 24, 2006 4:08 pm 
Newbie

Joined: Fri Mar 24, 2006 3:54 pm
Posts: 1
Does Hibernate support upsert/merge? In other words, automatically insert the record if it doesn't exist in the database and automatically update the record if it already does exist?

I have come across a scenario where this would come in handy. I have numerous threads which can potentially write to the same record in a table. If the record doesn't exist, it is supposed to insert. If it does exist, it is supposed to update. The problem is some of threads step on each other, so I get a constraint violation when some of the threads tries to insert at the "same time."

I could catch the contraint violation and force an update, but I was wondering if there was any way to make Hibernate manage it. Thanks!


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 24, 2006 4:16 pm 
Expert
Expert

Joined: Mon Jan 09, 2006 5:01 pm
Posts: 311
Location: Sacramento, CA
what is upsert?
anyhow there is session.saveOrUpdate().. but I think you are asking if there is a way to automate a merge of the object into the current session, if it is detached; and if that is the Q, then no I don't think there is - and you may get away with just calling session.saveOrUpdate(), having set the ID's properly on your objects (and in your mapping you'd need to specify the unsaved-value="null") - also assuming that your ID's are indeed objects and not literals.

_________________
-JT

If you find my replies helpful, please rate by clicking 'Y' on them. I appreciate it.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 13, 2006 4:31 pm 
Regular
Regular

Joined: Sat Jan 07, 2006 8:30 pm
Posts: 68
What about session.merge( detachedInstance ) ?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 14, 2006 10:30 pm 
Regular
Regular

Joined: Wed Jul 07, 2004 2:00 pm
Posts: 64
Also, what constraint violation are you getting? Mapping documents would be helpful.


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.