wood burning stoves
The moose likes Object Relational Mapping and the fly likes Optimistic Locking using versioning in EJB3 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of RabbitMQ in Depth this week in the Open Source forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Optimistic Locking using versioning in EJB3" Watch "Optimistic Locking using versioning in EJB3" New topic

Optimistic Locking using versioning in EJB3

shirish peshwe

Joined: Jul 30, 2009
Posts: 2
questions releated to optimistic locking in EJB 3
shirish peshwe

Joined: Jul 30, 2009
Posts: 2
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

Joined: Jul 20, 2009
Posts: 189
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.

I agree. Here's the link: http://aspose.com/file-tools
subject: Optimistic Locking using versioning in EJB3