-->
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: Does Hibernate lock an entity in the persistence context?
PostPosted: Sun Oct 11, 2009 11:39 pm 
Beginner
Beginner

Joined: Sat Feb 07, 2009 4:08 pm
Posts: 22
Location: New York City
I am a little confused by something.

If I have an entity that is loaded into a Persistence Context, and I need to add an element to a collection on that Entity, then perform a calculation based on the elements now contained in that collection and set a value in that entity based on the result of my calculation, and I do all of this within the same Persistence Context, is this safe to do?

Or, is there the danger that another user calling that same method could be modifying the same entity/collection at the same time and produce a race condition?

I am unclear on whether an entity loaded into the Persistence Context is in any way locked by Hibernate so as to prevent multiple threads from concurrently modifying the same entity. Or, do you have to synchronize the method to protect against this? Or can you/should you synchronize on the individual entity you have loaded in the persistence context?

Thank you for any help you can lend in clearing up my confusion on this point!

John


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.