Hi Dirk,
Kessler, Dirk wrote:
Armin, thanks for your reply.
We have transactions that span multiple web requests (pages) and we use
the PK values to identify objects that have been persisted on the
various pages (in order to re-display the contents of the objects if the
user goes back to one of those pages).
There are definitely many other ways we could have solved this problem
but re-using the IDs created by the makePersist method seemed the most
straightforward (since OJB makes sure that all of the IDs are unique).
I would suggest to use one of the OJB listener interface to get notified
about the new inserted objects:
http://db.apache.org/ojb/docu/guides/pb-guide.html#Hook+into+OJB+-+PB-Listener+and+Instance+Callbacks
http://db.apache.org/ojb/docu/guides/odmg-guide.html#Access+the+PB-api+within+ODMG
e.g. your class can implement PBLifeCycleListener and add itself (if
objects will be inserted) after the odmg-tx started as temporary
listener, then on t.commit you can read all PK's via
PBLifeCycleListener#afterInsert
Instead of the PK values you can use the OJB Identity object of each
persistent object, then you can re-display the objects via
PersistenceBroker#getObjectByIdeneity which is much faster than using an
OQL-query.
regards,
Armin
Thanks for your suggestion of using the SequenceManager.
-Dirk
-----Original Message-----
From: Armin Waibel [mailto:[EMAIL PROTECTED]
Sent: Tuesday, January 10, 2006 7:02 AM
To: OJB Users List
Subject: Re: OJB 1.0.4 and ODMG Database.makePersistent
Hi Dirk,
Kessler, Dirk wrote:
There appears to be a change in behavior in the
Database.makePersistent
method. In OJB 1.0RC7 the Database.makePersistent class would update
the
primary key field of the object being persisted (autoincrement) even
before the transaction was committed (I.E. right after the
makePersistent call). It appears that in OJB 1.0.4 the primary key
value
does not get updated until the transaction is committed.
yep, this change was needed to harmonize OJB behavior with
SequenceManager based on database identity columns. In this case it's
not possible to set the PK values when the object is stored
(#makePersistent call), only after the object is written to DB.
Only this way OJB will show the same behavior for all DB/PK-generation.
Is there any way to have makePersistent set the primary key value (it
can't be a transient value, it has to be the balue eventually stored
in
the database)?
It would be easy to implement a method which lookup the SequenceManager
obtain the next PK value and set this value in your object - but this
will cause some overhead.
Why do you need the "PK assign before store" functionality?
regards,
Armin
---------------------------------------------------------------------
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]