You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ojb-user@db.apache.org by Emmanuel Dupont <em...@jwaretechnologies.com> on 2003/04/07 11:05:23 UTC
Help : Transaction.upgrade on a primaryKey not works
All,
I have a table with only one column. This table is used by all my
application in order to have a unique Id for all my primary key tables.
I read this Primary Key table, increments it an then use this to create a
new line in any other table.
I use ODMG with PB. I don't manage to update this ID, OJB doesn't save my
upgrade. The newClient is created but the Id of my PrimakeyGenerator table
is not upgraded ???
Here is my source code.Very weird, I missed something again. Is it because
you can't update a primary key ?
Thanks for your help.
IDObject nextIdObject;
Client newClient = new Client();
// Obtain the current DB
Database db = odmg.getDatabase(null)
// Start transaction
tx = odmg.newTransaction();
tx.begin();
// Obtain a broker instance from the current transaction
broker = ((HasBroker) tx).getBroker();
try {
broker.beginTransaction();
// Unique Id management
query = new QueryByCriteria(IDObject, null);
Iterator iterid = broker.getIteratorByQuery(query);
// Commit the Db transaction
broker.commitTransaction();
nextIdObject = (IDObject) iterid.next();
// Lock the nextObject for update access
// (I also tried Transaction.Write, same bad result)
tx.lock(nextIdObject, JwtTransaction.UPGRADE);
// Increment the Id value
long id = nextIdObject.getID();
id ++;
nextObject.setID(id);
// Lock the newClient for write access
tx.lock(newClient, JwtTransaction.WRITE);
newClient.setName("Miller");
// Close the transaction
tx.commit();
[..]
Only the newClient is created, not the nextIdObject update..
If you have any comment on this source code don't hesitate.
Thanks a lot .!