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.  [ 1 post ] 
Author Message
 Post subject: Saving an entity if it doesn't exist
PostPosted: Mon Nov 06, 2006 6:24 pm 
Newbie

Joined: Mon Nov 06, 2006 6:19 pm
Posts: 16
Hello,
I think that my problem is more DB in nature, but maybe it's a good place to ask. I would like to add a new entity only if it doesn't exist (I have some unique constraints).

So I can:
1. Add the entity, and wait for a possible exception when I flush() the session - but then the whole transaction will be rolled back.
2. First do a select and only if nothing is found, add the entity - but this has problems with concurrent access (two threads checking at the same time that the entity does not exist, and trying to add it - one gets an exception).

Is there any way to do this properly (and in Hibernate), without setting the db isolation level to serializable?

--
Regards,
Adam Warski


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.