Hi,

Is it possible to select the same object two or more times and make some
changes to it in same transaction running in exclusive mode?

I gets this exception when I run the my example:
org.exolab.castor.jdo.PersistenceException: Lock conflict: attempt to
load object of type Account with identity 1 in two different locks modes
(exclusive and non exclusive) in the same transaction

Example:
import org.exolab.castor.jdo.*;

public class Test {
        
        public Test() throws Exception{         
                JDO jdo = new JDO();
                jdo.setDatabaseName( "test" );
                jdo.setConfiguration( "database.xml" );                               
                Database db = jdo.getDatabase();
                db.begin();
                
                step1(db);
                step2(db);
                        
                db.commit();
                db.close();
        }
        
        public void step1(Database db) throws Exception{
                OQLQuery oql = db.getOQLQuery("select a from Account a where id = 1");
                QueryResults rs = oql.execute();
                if(rs.hasMore()){
                        Account account = (Account)rs.next();
                        account.setName("test");
                        
                }
                rs.close();
                oql.close();
        }
        
        public void step2(Database db) throws Exception{
                OQLQuery oql = db.getOQLQuery("select a from Account a");
                QueryResults rs = oql.execute();
                while(rs.hasMore()){
                        Account account = (Account)rs.next();
                        System.out.println(account.getName());
                }
                rs.close();
                oql.close();            
        }       

        public static void main(String[] args) throws Exception{
                new Test();
        }

}

----------------------------------------------------------- If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
unsubscribe castor-dev




Reply via email to