Hi,
----- Original Message -----
From: "Farnea Massimiliano" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Thursday, March 06, 2003 12:58 PM
Subject: NEWBIE: cannot update object with ODMG
> I'm testing the ODMG layer with this example:
>
> /**
> * Update the Traente instance on the database
> */
>
> public void update() {
>
> Database db = odmg.newDatabase(); // the current DB
> Transaction tx = null;
> //open database
> try {
> db.open("default", Database.OPEN_READ_WRITE);
> } catch (ODMGException ex) {
> ex.printStackTrace();
> }
>
> tx = odmg.newTransaction();
> String oqlQuery = "select edit from " +
> traente.className +
> " where id = " + traente.getId();
> try {
> tx = odmg.newTransaction();
you got 2 transactions now. I think you need only one.
> tx.begin();
>
> OQLQuery query = odmg.newOQLQuery();
> query.create(oqlQuery);
> DList result = (DList) query.execute();
> Traente toBeEdited = (Traente) result.get(0);
>
> tx.lock(toBeEdited, Transaction.UPGRADE);
At the tutorial page the OJB crew uses
tx.lock(toBeEdited, Transaction.WRITE);
for updating values.
>
> toBeEdited = traente;
what's traente at that point?
> tx.commit();
second transaction is commited but the first one is still in use.
cheers,
Guido
> } catch (Throwable t) {
> // rollback in case of errors
> tx.abort();
> t.printStackTrace();
> }finally {
> try {
> db.close();
> System.out.println("DB closed!!!!");
> } catch (ODMGException ex) {
> ex.printStackTrace();
> }
> }
> }
>
>
> where 'traente' is a class attribute that rapresents the updated object
that
> i would like to persist.
>
> After the method invocation .... the database still contains the old
object,
> while retrieving again the reference 'toBeEdited' it seems to be updated.
> What do I miss? I'm using a test class on JBuilder, without any particular
> deployement enviroment.
>
> Thanks in advance
>
> Massimiliano Farnea
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]