Hi Kanwar, Why are you checking for null? Just set the PK.
mrg On Fri, Jul 27, 2012 at 4:19 AM, KM <[email protected]> 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 here? > > Thanks > Kanwar Manish > > > Michael Gentry-2 wrote >> >> Hi Joel, >> >> What version of Cayenne are you using? If 3.0, you'll probably want >> to use a callback. If 2.0, use setPersistenceState. For 3.0, you'd >> be interested in the PostAdd callback: >> >> http://cayenne.apache.org/doc30/lifecycle-callbacks.html >> >> Configure the callback in Cayenne Modeler with a name such as >> "onPostAdd" and then in your Java: >> >> @Override >> protected void onPostAdd() >> { >> ... >> } >> >> mrg >> >> >> >> On Thu, Sep 8, 2011 at 11:03 AM, Becker, Joel <joel.becker@> wrote: >>> >>> >>> https://cwiki.apache.org/CAY/setting-initial-values.html says "the best >>> place to set default/initial values in the newly created object is in >>> the setPersistenceState". Is there a problem with setting the default >>> values in a default constructor (following java general best practices)? >>> >>> >> > > > > > -- > View this message in context: > http://cayenne.195.n3.nabble.com/Can-default-values-be-set-in-Constructor-instead-of-setPersistenceState-tp3320047p4024463.html > Sent from the Cayenne - User mailing list archive at Nabble.com.
