Hi Walid,
I also have got a singleton class with a similar store() code than you.
At least in singleVM mode it works fine for me, but in C/S mode I have
problems, but I don't know yet if it's because of the singleton and/or
the upcast to Object. Will try more today.
Writing update code in a singleton class is difficult, because the
object has to be locked BEFORE it is changed:
tx.begin();
pobj = query(persistentObject.class); // put a real query here
tx.lock(pobj, tx.WRITE);
pobj.setName("Walid"); //change the Name here
tx.commit();
Probabably you could play around with something like this, but I DID NOT
TRY THIS:
pobj = query(persistentObject.class); // put a real query here
pobjUpdate = pobj;
pobjUpdate.setName=("Walid);
update(pobj, pobjUpdate);
public void update(Object toBeUpdated, Object update) {
tx.begin();
tx.lock(toBeUpdated, tx.WRITE);
toBeUpdated = update; //the object is exchanged for a new one.
tx.commit();
}
/olaf
Walid Ahmed wrote:
>Hi!
>
>I've spent now 5h on finding out the following behaviour:
>There is a significant difference between storing new objects and storing existing
>but edited objects.
>The latter seems to work only if properties are edited between the transaction
>beginning and the commitment. Right??
>I wanted to use the following method in a singleton ControlClass.
>
> public void store(Object toBeStored) {
> Database db = odmg.getDatabase(null); // the current DB
> Transaction tx = null;
> tx = odmg.newTransaction();
> tx.begin();
> tx.lock(toBeStored, tx.WRITE);
> tx.commit();
> }
>
>So in one case I put in a newly created Object (OID==0 ?) and in another case its an
>object that I retrieve from DB to change some properties.
>The first case works fine, but in the second I just get the following:
>
>[org.apache.ojb.broker.singlevm.PersistenceBrokerImpl] DEBUG: getObjectByIdentity
>de.itconcept.bbs.server.company.data.Address{21}
>
>But there is no UPDATE executed against the DB.
>Sometimes (!) its followed by a debug output about what SELECT statement was used for
>getting an Address.
>
>What can I do?? I'dont want to move the transaction outside of the store function.
>Are there possibilities to store Objects without beginning and comitting
>transactions?
>Can I use an alternative method than tx.lock(toBeStored,tx.WRITE) ?
>Why does db.makePersistent(toBeStored) does'nt work either?
>
>Thank You all for helping
>
>Walid
>
>
>
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>