Here is some code to make my enquiry more clear.

The version_lock optimistic strategy in JBoss 4.0.0 has been setup
correctly as the version_lock field autoincrements after every commit.
Both the session bean and the entity bean are marked as Required
in the ejb-jar.xml. 

My main question is if this is the correct way to implement optimistic
locking with JBoss. I cannot think of another way other than client
initiated transaction to include the
user input time inside the same transaction where
the retrieval and save of the data takes place.

If I remove the userTrans.begin and .commit statements JBoss
never throws the following exception when 2 users edit the same record.

org.jboss.tm.JBossRollbackException: Unable to commit, 
tx=TransactionImpl:XidImpl[FormatId=257, GlobalId=c1700p/14, BranchQual=, 
localId=14] status=STATUS_NO_TRANSACTION; - nested throwable: 
(javax.ejb.EJBException: Update failed. Expected one affected row: 
rowsAffected=0, id=10)

Client Code
(I want to make a web application but I use this 
simple command line application to demonstrate my problem)



  | 
  | UserTransaction userTran = (UserTransaction)ctx.lookup("UserTransaction");
  |         
  | userTran.begin();
  |         
  | mySessionBean aSessionBean = aSessionHome.create();
  | PersonData data = aSessionBean.retrieve(); // Getting the value object
  | 
  | System.out.println("This is the information requested:");
  | System.out.println(data);
  | System.out.println("Please edit the name:");
  |         
  | data.setName(buf.readLine());     
  | aSessionBean.updatePerson(data);
  |         
  | userTran.commit();
  | 
  | 


jboss.xml

<container-configurations>    
  |       <container-configuration extends="Instance Per Transaction CMP 2.x 
EntityBean"> 
  |         <container-name>Optimistic CMP EntityBean</container-name> 
  |         
<locking-policy>org.jboss.ejb.plugins.lock.JDBCOptimisticLock</locking-policy>
  |       </container-configuration> 
  |     </container-configurations>


jbosscmp-jdbc.xml

<optimistic-locking>       
  |           <version-column/>
  |             <field-name>version_lock</field-name>        
  |             <column-name>VERSION_LOCK</column-name>
  |         </optimistic-locking>



View the original post : 
http://www.jboss.org/index.html?module=bb&op=viewtopic&p=3859162#3859162

Reply to the post : 
http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=3859162


-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now. 
http://productguide.itmanagersjournal.com/
_______________________________________________
JBoss-user mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-user

Reply via email to