aspose file tools*
The moose likes EJB and other Java EE Technologies and the fly likes How to Achive Transaction Concurrency in EJB 3 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "How to Achive Transaction Concurrency in EJB 3 " Watch "How to Achive Transaction Concurrency in EJB 3 " New topic
Author

How to Achive Transaction Concurrency in EJB 3

udaya ranasinghe
Greenhorn

Joined: Dec 10, 2009
Posts: 1
I want to handle transaction concurrency in my project.
I read about the @Version but i couldn't understand the concept.
Can anybody give example code and explanation for that?

Devaka Cooray
ExamLab Creator
Saloon Keeper

Joined: Jul 29, 2008
Posts: 3102
    
  40

Hello Udaya Welcome to JavaRanch.

That's the optimistic locking feature which can be used to prevent inappropriate usage of concurrent updates over an entity in the database. Simply you can use this @Version annotation to annotate a property of a primary entity.

Now, the version property manages a version value for the given entity in the database. It gets assigned a new value at each commit (to the database). In a concurrent scenario, let's say that the attributes in the same entity gets concurrently modified. Then, the first commit will be successful, because the version value in the entity instance, and which was in the database are identical to each other. This value will be changed once it is committed. After that, the second concurrent modification will not be allowed to commit - because the version value which IS in the database is different than the value in the entity instance itself. On that case OptimisticLockException will be thrown when you attempt to commit (or flush) the entity instance which has an incorrect version value. If there is an active transaction, that will be (marked) rolled-back so that it prevents the concurrent problem.

Devaka.


Author of ExamLab ExamLab - a free SCJP / OCPJP exam simulator
What would SCJP exam questions look like? -- Home -- Twitter -- How to Ask a Question
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19697
    
  20

Moving to EJB.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to Achive Transaction Concurrency in EJB 3