Hi Emmanuel, don't call broker.commitTransaction();
what does jwtImpl.newJwtTransaction(); do? does it really instantiate a *new* transaction? I have the impression that you work on the same transaction instance and try to re-use the already closed broker transaction... cheers, thomas > -----Original Message----- > From: Emmanuel Dupont [mailto:[EMAIL PROTECTED] > Sent: Tuesday, June 17, 2003 12:53 PM > To: OJB Users List > Subject: Lock bug ?? > > > Hi all, > > > > Can someone tell me what is wrong with this piece of code ?? > I'm using OJB, > rc1. > > > > > > When I call this method twice it failed on the second call on > the lock line. > I have only one column in my table. IT is an OID table generator. > > Whith : > > > > [org.apache.ojb.odmg.TransactionImpl] INFO: Abort transaction > was called on > tx [EMAIL PROTECTED], > associated PB was > [EMAIL PROTECTED] > > [org.apache.ojb.broker.accesslayer.ConnectionManagerImpl] > INFO: Rollback was > called, do rollback on current connection > [EMAIL PROTECTED] > > [BOjects] null > > java.lang.ClassCastException > > TransactionImpl.lock(JwtTransactionImpl.java:86) > > BOjects.getNextOId(BOjects.java:112) > > org.apache.ojb.broker.TransactionNotInProgressException: > ConnectionManager > is NOT in transaction > > at > org.apache.ojb.broker.singlevm.PersistenceBrokerImpl.commitTra > nsaction(Persi > stenceBrokerImpl.java:390) > > at > org.apache.ojb.broker.singlevm.DelegatingPersistenceBroker.com > mitTransaction > (DelegatingPersistenceBroker.java:117) > > at BOjects.getNextOId(JwtBOjects.java:124) > > Exception in thread "main" > > > > > > When I try to parse the code in the debugger, I doesn't > failed ..??? Does > that means there is some synchronization problems ? > > > > Tx, a lot, any help would be appreciated.. > > > > -------------------------------------------- > > public long getNextOId(Class oidObjectClass) { > > JwtTransaction tx = jwtImpl.newJwtTransaction(); > > tx.begin(); > > JwtDatabase db = jwtImpl.getJwtDatabase(null); > > > > PersistenceBroker broker = ((HasBroker) tx).getBroker(); > > broker.beginTransaction(); > > > > long result = -1; > > > > try { > > Query query = new QueryByCriteria(oidObjectClass, null); > > > > IObject oidObject = (IObject) broker.getObjectByQuery(query); > > > > // Check and increment the Oid ID > > result = oidObject.getId(); > > > > // Delete the old oidObject > > db.deletePersistent(oidObject); > > > > // Create a new OidObject > > oidObject newOidObject = new oidObject (); > > > > // Lock the nextObject for write access > > tx.lock(newOidObject, WRITE); ///FAILED ON THE SECOND CALL > > > > // Set the modification > > oidObject.setId(result+1); > > > > } catch (Exception e) { > > // rollback in case of errors > > tx.abort(); > > System.err.println("[BOjects] " + e.getMessage()); > > e.printStackTrace(); > > } > > > > broker.commitTransaction(); > > tx.commit(); > > > > return result; > > } > > --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
