File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Object Relational Mapping and the fly likes Should JPA handle concurrent updates? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Object Relational Mapping
Reply Bookmark "Should JPA handle concurrent updates?" Watch "Should JPA handle concurrent updates?" New topic
Author

Should JPA handle concurrent updates?

Robert Willems
Ranch Hand

Joined: Apr 14, 2003
Posts: 32
Hi all,

just a question i'm puzzling on at the moment. Should JPA implementations throw something like 'ConcurrentModificationException' when two instances of an application modify the same row?

Or in other words: should JPA solve the lost update problem?

Or in even other words:
User A retrieves Record A
User B retrieves Record A
User A updates Record A and stores it
User B updates Record A and stores it (and gets an exception?)

Thanks for any help...

Regards,
Robert

Ps. Using JPA through Spring and implemented by hibernate 3.2


Regards,<br />Robert Willems of Brilman<br /> <br />----------------------<br /> <br />SCJP 1.4<br />SCWCD 1.3<br />SCWCD 1.4 (beta)<br />SCDJWS 1.4 (beta)<br />SCBCD 1.3 (studying)
Edvins Reisons
Ranch Hand

Joined: Dec 11, 2006
Posts: 364
The term used in the JPA specification is "optimistic locking" and the exception thrown is "OptimisticLockException".
Robert Willems
Ranch Hand

Joined: Apr 14, 2003
Posts: 32
Hi,

thanks! I found that i should use the @Version annotation to get the required functionality...

Regards,
Robert
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 16622

So as Edvins pointed out. If you don't implement optimistic locking then JPA will have Lost Updates.

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
 
 
subject: Should JPA handle concurrent updates?
 
Threads others viewed
NX: URLyBird Database Record Number Question
Seam and persistence context management
Locking the record in DB and showing it on the browser page.
How to achive Optimistic Locking for an Application
(URLyBird) 1.3.1 reusage of deleted entries
IntelliJ Java IDE