Hi,

Jose Maria Lopez Lagunas wrote:
Hi.

I'm having some problems with the state of some persistent objects. I've looking for examples in Internet but all ODMG examples are pretty simple.


You won't find much about this on the web, as ODMG does not specify how an
implementation should work.
I designed the OJB ODMG do work like the JDO spec. That is we also have an
instance lifecycle in OJB ODMG.
You'll find more about the instance lifecycle model in the JDO spec!

If you want to find out how the OJB lifecycle works have a look at the
classes in org.apache.ojb.odmg.states




I'll show you an example of what I mean:

tx.begin(); // Begin transaction
MyObj o = new MyObj(); // A new MyObj instance is created and it gets the correct ID (primary key)
db.makePersistent(o); // Make persistent
as the Object is new it is marked as StateNewDirty.

o.setWhatever("Value");     // Modify the object
db.deletePersistent(o);         // Mark object to be deleted
now we have a statetransition to StateNewDelete (see method StateNewDirty.markDelete())

tx.commit();                            // Commit transaction

During commit all objects are checked against their initial state to compute the proper State to perform the database operations.
During this check OJB detects that the object had been modified and thus performs a new (implicit) Statetransition by invoking .markDirty().
StateNewDelete.markDirty() returns StateNewDirty !

Then the work is commited and StateNewDirty results in an INSERT operation!

If you don't modify the Object in the tx, OJB won't insert it!

I think the persistence layer should do nothing since it's a new persistent object and the last operation was to delete it. For whatever reason, OJB realizes that it was modified and stores in the database, although the modifications were done before marking it to be deleted.

I would like someone will explain that to me.
Explanation given above. Of course you won't be happy with my "works as designed" answer.
Maybe the logic should be changed to not mark StateXxxDelete Objects as dirty?

cheers,
Thomas

Thank you in advance.

Jose Maria


--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>






--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to