• Post Reply Bookmark Topic Watch Topic
  • New Topic

Should JPA handle concurrent updates?  RSS feed

 
Robert Willems
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Edvins Reisons
Ranch Hand
Posts: 364
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The term used in the JPA specification is "optimistic locking" and the exception thrown is "OptimisticLockException".
 
Robert Willems
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

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

Regards,
Robert
 
Mark Spritzler
ranger
Sheriff
Posts: 17309
11
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So as Edvins pointed out. If you don't implement optimistic locking then JPA will have Lost Updates.

Mark
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!