Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Optimistic Locking using versioning in EJB3

 
shirish peshwe
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
questions releated to optimistic locking in EJB 3
 
shirish peshwe
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Realted to optimistic locking using @version field -- "If you dont specify an @version field, the entity manager has to walk through each field in entity insatnce and compare its value to corresponding, mapped column in the database, which is far more laborious"

Statement is taken from "Beginning EJB 3 application development" By RaghuR. Kodali, Jonathan Wetherbee, Peter Zadrozny -- Page 142- para 1

Does this statement means, even if i dont use "@version" still it will give me optimisticLockException by checking column in database if its updated??? .... How???

Link for above page in books.google : http://books.google.com/books?id=xnbJkOIZfFgC&pg=PA141&lpg=PA141&dq=example+of+optimistic+locking+in+EJB3&source=bl&ots=Eb_QWTE2gy&sig=mGDm0rMY8vVJ0c3RzWaL31MA20c&hl=en&ei=RtttSoL3GYSksgOWwqjKDg&sa=X&oi=book_result&ct=result&resnum=1
 
Christian Dillinger
Ranch Hand
Posts: 197
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This behaviour is not included in JPA! It's a hibernate feature. JPA only known versioning using a version attribute.

In hbm.xml you can set <class... optimistic-lock="all"> so Hibernate lists the last value of all fields in an update statement.
E.g. "update xyz set foo = ?, bar =? where id = 123 and foo ='bla' and bar = 'blubb'".

With Annotations you can do the same with "@org.hibernate.annotations.Entity(optimisticLock = org.hibernate.annotations.OptimisticLockType.ALL)

If you use JBoss you have Hibernate as JPA-provider, so you don't have to deploy any additional libs.

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic