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
|