cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Michael Gentry <>
Subject Re: Life cycle callback onPostAdd doesn't seem to be working
Date Fri, 27 Jul 2012 20:59:32 GMT
Hi Kanwar,

I answered this in another thread, but here is a better explanation
for you.  You don't need to check for null in onPostAdd() and you
especially don't need to check if getObjectId() is null (it won't be,
since it is in a DataContext).  If you did need to check for null for
some reason, perhaps check if getLogicalFolderId() returns null.  All
new objects registered in a DataContext have a temporary objectID
(hence it will not be null) and all persisted objects have a permanent
objectID (which also will not be null), therefore none of your Cayenne
objects should ever have a null objectID if residing in a DataContext.


On Fri, Jul 27, 2012 at 7:14 AM, Kanwar Manish <> wrote:
> I am using Cayenne 3.1B1.
> Overriding onPostAdd is not working. I have added the callback in the
> modeller added the code below
>     @Override
>     protected void onPostAdd()
>     {
>         if (getObjectId() == null)
>         {
>         setLogicalFolderId(UUID.
> randomUUID().toString());
>         }
>     }
> Basically - trying to initialize the Primary Key - but this is not working.
> When adding multiple related objects - id's of the objects obtained through
> - context.newObject() are not having any id.
> Can you point me - what am I doing wrong/missing here?
> Thanks
> Kanwar Manish

View raw message