cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Hugi Thordarson <>
Subject Re: Obtain primary key for DataObject before commitChanges
Date Mon, 10 Aug 2015 14:06:23 GMT
>> Is it possible for me to obtain the primary key for a Cayenne DataObject before committing
changes? I’m writing an audit log and I need the key for the object during PrePersist (where
I’m constructing the log object).
> How will it have a primary key before the record is written to the database? Or do you
want to hang onto the temporary ObjectId and then replace it with the real PK after the commit?

Well, in EOF (to mention that old chap yet again) I invoked permanentGlobalID() on the object.
That meant that if the object had a temporary GlobalID, it would make a roundtrip to the DB
and assign a permanent ID without actually saving the object.

But I realized I’m actually going about this the wrong way. If I do the logging in PostPersist
rather than PrePersist, the object already has a permanent ID, so no premature PK generation
is required :).

- hugi
View raw message