Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

OptimisticLockException example

 
Jacek Laskowski
Ranch Hand
Posts: 42
IntelliJ IDE Mac OS X Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I've been trying to create a sample application that would finish with the exception - OptimisticLockException - being thrown but with no joy so far. Could anyone lend me a helping hand with the task?

Jacek
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK, which API throws that exception? Are you using an ORM tool?
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is based on using a version field in your class and mapping with <version> or @Version in Hibernate. So if one client updates a record, and another tries to update the same record but has stale data. But doesn't that throw a StaleDataException?

Any way open one session, get the record and assign to one var. Then close the session, open another session and get the record again and assign to a different var. Then close the session. change the first var, Open a new sesssion and save the var, then close the session. Open another session, and change the second var, using the same attribute that you changed, and then try to save that one, and see what happens.

Mark
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic