Hi Emmanuel,

did you have tried without
broker.begin...
broker.commit...
statements?

regards,
Armin

----- Original Message -----
From: "Emmanuel Dupont" <[EMAIL PROTECTED]>
To: "OJB Users List" <[EMAIL PROTECTED]>
Sent: Tuesday, June 17, 2003 12:53 PM
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.commitTransaction(P
ersi
stenceBrokerImpl.java:390)

      at
org.apache.ojb.broker.singlevm.DelegatingPersistenceBroker.commitTransac
tion
(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]

Reply via email to