I was trying a simple Test program. where I am setting a set of objects and what to 
write them  in a DB.I am using PB Api. The very first write is a success but throwing 
exception from 2nd write onwards. What I am doing wrong ?
 
org.apache.ojb.broker.OptimisticLockException: Object has been modified by someone else
 at Test1.main2(Test1.java:64)
 at Test1.<init>(Test1.java:23)
 at Test1.main(Test1.java:27)
Caused by: org.apache.ojb.broker.OptimisticLockException: Object has been modified by 
someone else
 at org.apache.ojb.broker.accesslayer.JdbcAccess.executeUpdate(Unknown Source)
 at org.apache.ojb.broker.singlevm.PersistenceBrokerImpl.storeToDb(Unknown Source)
 at org.apache.ojb.broker.singlevm.PersistenceBrokerImpl.store(Unknown Source)
 at org.apache.ojb.broker.singlevm.PersistenceBrokerImpl.store(Unknown Source)
 at org.apache.ojb.broker.singlevm.PersistenceBrokerImpl.store(Unknown Source)
 at org.apache.ojb.broker.singlevm.DelegatingPersistenceBroker.store(Unknown Source)
  
Here is my caller method: 
    
public Test1 ()
 {
  main2();
  main2();
 }

And here is the called method 

    public void main2 ( )
{
    PersistenceManager pm = null;
    Transaction tx = null;
    Sample zs = new Sample();
    zs.setAttr1((long)10);
    zs.setAttr2(30);
     zs.setAttr3((long)40);        
 
    try {
     pm = PersistenceManager.getInstance(); // return Broker.defaultPersistenceBroker()
     pm.beginTransaction();
     pm.Store(zs);
     pm.commitTransaction();
     
 }
 catch (Exception ex) { 
     ex.printStackTrace();
     System.out.println("Error in Test1 1 ");
     try {
         if ( tx != null )
              pm.abortTransaction();

     catch (Exception ex1) {
     }
 }
    

 

Reply via email to