You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cayenne.apache.org by "Becker, Joel" <jo...@essvote.com> on 2011/09/08 17:03:01 UTC
Can default values be set in Constructor instead of setPersistenceState()?
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)?
Re: Can default values be set in Constructor instead of setPersistenceState()?
Posted by Andrus Adamchik <an...@objectstyle.org>.
Yes, you can set values in constructor, but keep in mind that persistent object has a certain lifecycle. So constructor can be called for the NEW objects that you create, as well as for COMMITTED objects fetched by Cayenne from DB. Those 2 cases are very likely to require different initialization.
The advice about lifecycle events at the top of the page alludes to this fact.
Andrus
On Sep 8, 2011, at 11:03 AM, Becker, Joel 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)?
>
Re: Can default values be set in Constructor instead of setPersistenceState()?
Posted by Michael Gentry <mg...@masslight.net>.
Hi Kanwar,
ObjectContext is an interface. You are most likely actually using a
DataContext, which inherits from BaseContext (which implements
ObjectContext).
mrg
On Fri, Aug 3, 2012 at 7:04 AM, Kanwar Manish <ka...@gmail.com> wrote:
> Hey Thanks again
>
> This worked out like a charm.
>
> But I am using ObjectContext for creating my objects. I hope that is not
> the problem?
>
> Thanks
> Kanwar Manish
>
> On Fri, Aug 3, 2012 at 3:54 PM, Andrus Adamchik <an...@objectstyle.org>wrote:
>
>> I am an Eclipse user.. I have no NetBeans experience at all unfortunately.
>>
>> But you can get the source jars matching Cayenne binary jars straight from
>> Maven repo. Here is the one you likely need:
>>
>>
>> http://search.maven.org/remotecontent?filepath=org/apache/cayenne/cayenne-server/3.1B1/cayenne-server-3.1B1-sources.jar
>>
>> Andrus
>>
>> On Aug 3, 2012, at 1:16 PM, Kanwar Manish wrote:
>>
>> > Thanks Andrus.
>> >
>> > I am afraid that will be a bit tough for me - for now. I am a complete
>> Java
>> > and Linux noob, coming from .NET background.
>> >
>> > I tried attaching 3.1B1 source to the binaries [in Netbeans 7.2] but
>> > failed. I just can't figure out which source folder to attach with which
>> > Cayenne Jar [Client, server, tools or lifecycle].
>> >
>> > Can anybody help me out here please?
>> >
>> > Thanks
>> > Manish
>> >
>> >
>> >
>> > On Fri, Aug 3, 2012 at 1:28 PM, Andrus Adamchik <andrus@objectstyle.org
>> >wrote:
>> >
>> >> Hi,
>> >>
>> >> I am not aware of any issues with PostAdd. Your best bet is to debug
>> >> inside Cayenne DataContext.newObject(..). Specifically in BaseContext
>> there
>> >> is a method "injectInitialValue" that has this line at the end:
>> >>
>> >> // invoke callbacks
>> >> getEntityResolver().getCallbackRegistry().performCallbacks(
>> >> LifecycleEvent.POST_ADD,
>> >> object);
>> >>
>> >> This is where callbacks are invoked. Please share what you find here,
>> and
>> >> maybe based on those clues we can unwind it further.
>> >>
>> >> Cheers,
>> >> Andrus
>> >>
>> >>
>> >> On Aug 3, 2012, at 9:08 AM, KM wrote:
>> >>
>> >>> Removed the check for the key.
>> >>>
>> >>> It seems that the problem is that this is not getting fired at all.
>> >>> Breakpoint is not being hit. This is strange.
>> >>>
>> >>> I have checked for the abstract declaration in the parent class.
>> Setting
>> >>> this up in the modeler.
>> >>>
>> >>> Has anyone faced this problem before?
>> >>>
>> >>> Thanks
>> >>> Kanwar Manish
>> >>>
>> >>>
>> >>>
>> >>> --
>> >>> View this message in context:
>> >>
>> http://cayenne.195.n3.nabble.com/Can-default-values-be-set-in-Constructor-instead-of-setPersistenceState-tp3320047p4024479.html
>> >>> Sent from the Cayenne - User mailing list archive at Nabble.com.
>> >>>
>> >>
>> >>
>>
>>
Re: Can default values be set in Constructor instead of setPersistenceState()?
Posted by Kanwar Manish <ka...@gmail.com>.
Thanks Andrus and MRG
Thankyou all for this much support.
I can see at the breakpoint that it is indeed a DataContext only.
Unfortunately I need some help from a NetBeans guy since even after
attaching the source - I can't step into the newObject code.
Error I get while trying to set a breakpoint for injectInitialValue is
"Not able to submit breakpoint LineBreakpoint BaseContext.java : 638,
reason: No source root found for URL
'jar:file:/home/manish/Downloads/cayenne-server-3.1B1-sources.jar!/org/apache/cayenne/BaseContext.java'.
Verify the setup of project sources.
"
I think if I can cross this - I am close to finding something for sure.
Anybody from the netbeans background please - your help is badly required?
Thanks
Kanwar Manish
On Fri, Aug 3, 2012 at 5:02 PM, Andrus Adamchik <an...@objectstyle.org>wrote:
> ObjectContext is an interface... When you are dealing with an object in
> debugger, the instance will be of a specific implementation type (there
> can't be an instance of an interface obviously). Which is normally
> DataContext. So yes, not a problem.
>
> On Aug 3, 2012, at 2:04 PM, Kanwar Manish wrote:
>
> > Hey Thanks again
> >
> > This worked out like a charm.
> >
> > But I am using ObjectContext for creating my objects. I hope that is not
> > the problem?
> >
> > Thanks
> > Kanwar Manish
> >
> > On Fri, Aug 3, 2012 at 3:54 PM, Andrus Adamchik <andrus@objectstyle.org
> >wrote:
> >
> >> I am an Eclipse user.. I have no NetBeans experience at all
> unfortunately.
> >>
> >> But you can get the source jars matching Cayenne binary jars straight
> from
> >> Maven repo. Here is the one you likely need:
> >>
> >>
> >>
> http://search.maven.org/remotecontent?filepath=org/apache/cayenne/cayenne-server/3.1B1/cayenne-server-3.1B1-sources.jar
> >>
> >> Andrus
> >>
> >> On Aug 3, 2012, at 1:16 PM, Kanwar Manish wrote:
> >>
> >>> Thanks Andrus.
> >>>
> >>> I am afraid that will be a bit tough for me - for now. I am a complete
> >> Java
> >>> and Linux noob, coming from .NET background.
> >>>
> >>> I tried attaching 3.1B1 source to the binaries [in Netbeans 7.2] but
> >>> failed. I just can't figure out which source folder to attach with
> which
> >>> Cayenne Jar [Client, server, tools or lifecycle].
> >>>
> >>> Can anybody help me out here please?
> >>>
> >>> Thanks
> >>> Manish
> >>>
> >>>
> >>>
> >>> On Fri, Aug 3, 2012 at 1:28 PM, Andrus Adamchik <
> andrus@objectstyle.org
> >>> wrote:
> >>>
> >>>> Hi,
> >>>>
> >>>> I am not aware of any issues with PostAdd. Your best bet is to debug
> >>>> inside Cayenne DataContext.newObject(..). Specifically in BaseContext
> >> there
> >>>> is a method "injectInitialValue" that has this line at the end:
> >>>>
> >>>> // invoke callbacks
> >>>> getEntityResolver().getCallbackRegistry().performCallbacks(
> >>>> LifecycleEvent.POST_ADD,
> >>>> object);
> >>>>
> >>>> This is where callbacks are invoked. Please share what you find here,
> >> and
> >>>> maybe based on those clues we can unwind it further.
> >>>>
> >>>> Cheers,
> >>>> Andrus
> >>>>
> >>>>
> >>>> On Aug 3, 2012, at 9:08 AM, KM wrote:
> >>>>
> >>>>> Removed the check for the key.
> >>>>>
> >>>>> It seems that the problem is that this is not getting fired at all.
> >>>>> Breakpoint is not being hit. This is strange.
> >>>>>
> >>>>> I have checked for the abstract declaration in the parent class.
> >> Setting
> >>>>> this up in the modeler.
> >>>>>
> >>>>> Has anyone faced this problem before?
> >>>>>
> >>>>> Thanks
> >>>>> Kanwar Manish
> >>>>>
> >>>>>
> >>>>>
> >>>>> --
> >>>>> View this message in context:
> >>>>
> >>
> http://cayenne.195.n3.nabble.com/Can-default-values-be-set-in-Constructor-instead-of-setPersistenceState-tp3320047p4024479.html
> >>>>> Sent from the Cayenne - User mailing list archive at Nabble.com.
> >>>>>
> >>>>
> >>>>
> >>
> >>
>
>
Re: Can default values be set in Constructor instead of setPersistenceState()?
Posted by Andrus Adamchik <an...@objectstyle.org>.
ObjectContext is an interface... When you are dealing with an object in debugger, the instance will be of a specific implementation type (there can't be an instance of an interface obviously). Which is normally DataContext. So yes, not a problem.
On Aug 3, 2012, at 2:04 PM, Kanwar Manish wrote:
> Hey Thanks again
>
> This worked out like a charm.
>
> But I am using ObjectContext for creating my objects. I hope that is not
> the problem?
>
> Thanks
> Kanwar Manish
>
> On Fri, Aug 3, 2012 at 3:54 PM, Andrus Adamchik <an...@objectstyle.org>wrote:
>
>> I am an Eclipse user.. I have no NetBeans experience at all unfortunately.
>>
>> But you can get the source jars matching Cayenne binary jars straight from
>> Maven repo. Here is the one you likely need:
>>
>>
>> http://search.maven.org/remotecontent?filepath=org/apache/cayenne/cayenne-server/3.1B1/cayenne-server-3.1B1-sources.jar
>>
>> Andrus
>>
>> On Aug 3, 2012, at 1:16 PM, Kanwar Manish wrote:
>>
>>> Thanks Andrus.
>>>
>>> I am afraid that will be a bit tough for me - for now. I am a complete
>> Java
>>> and Linux noob, coming from .NET background.
>>>
>>> I tried attaching 3.1B1 source to the binaries [in Netbeans 7.2] but
>>> failed. I just can't figure out which source folder to attach with which
>>> Cayenne Jar [Client, server, tools or lifecycle].
>>>
>>> Can anybody help me out here please?
>>>
>>> Thanks
>>> Manish
>>>
>>>
>>>
>>> On Fri, Aug 3, 2012 at 1:28 PM, Andrus Adamchik <andrus@objectstyle.org
>>> wrote:
>>>
>>>> Hi,
>>>>
>>>> I am not aware of any issues with PostAdd. Your best bet is to debug
>>>> inside Cayenne DataContext.newObject(..). Specifically in BaseContext
>> there
>>>> is a method "injectInitialValue" that has this line at the end:
>>>>
>>>> // invoke callbacks
>>>> getEntityResolver().getCallbackRegistry().performCallbacks(
>>>> LifecycleEvent.POST_ADD,
>>>> object);
>>>>
>>>> This is where callbacks are invoked. Please share what you find here,
>> and
>>>> maybe based on those clues we can unwind it further.
>>>>
>>>> Cheers,
>>>> Andrus
>>>>
>>>>
>>>> On Aug 3, 2012, at 9:08 AM, KM wrote:
>>>>
>>>>> Removed the check for the key.
>>>>>
>>>>> It seems that the problem is that this is not getting fired at all.
>>>>> Breakpoint is not being hit. This is strange.
>>>>>
>>>>> I have checked for the abstract declaration in the parent class.
>> Setting
>>>>> this up in the modeler.
>>>>>
>>>>> Has anyone faced this problem before?
>>>>>
>>>>> Thanks
>>>>> Kanwar Manish
>>>>>
>>>>>
>>>>>
>>>>> --
>>>>> View this message in context:
>>>>
>> http://cayenne.195.n3.nabble.com/Can-default-values-be-set-in-Constructor-instead-of-setPersistenceState-tp3320047p4024479.html
>>>>> Sent from the Cayenne - User mailing list archive at Nabble.com.
>>>>>
>>>>
>>>>
>>
>>
Re: Can default values be set in Constructor instead of setPersistenceState()?
Posted by Kanwar Manish <ka...@gmail.com>.
Hey Thanks again
This worked out like a charm.
But I am using ObjectContext for creating my objects. I hope that is not
the problem?
Thanks
Kanwar Manish
On Fri, Aug 3, 2012 at 3:54 PM, Andrus Adamchik <an...@objectstyle.org>wrote:
> I am an Eclipse user.. I have no NetBeans experience at all unfortunately.
>
> But you can get the source jars matching Cayenne binary jars straight from
> Maven repo. Here is the one you likely need:
>
>
> http://search.maven.org/remotecontent?filepath=org/apache/cayenne/cayenne-server/3.1B1/cayenne-server-3.1B1-sources.jar
>
> Andrus
>
> On Aug 3, 2012, at 1:16 PM, Kanwar Manish wrote:
>
> > Thanks Andrus.
> >
> > I am afraid that will be a bit tough for me - for now. I am a complete
> Java
> > and Linux noob, coming from .NET background.
> >
> > I tried attaching 3.1B1 source to the binaries [in Netbeans 7.2] but
> > failed. I just can't figure out which source folder to attach with which
> > Cayenne Jar [Client, server, tools or lifecycle].
> >
> > Can anybody help me out here please?
> >
> > Thanks
> > Manish
> >
> >
> >
> > On Fri, Aug 3, 2012 at 1:28 PM, Andrus Adamchik <andrus@objectstyle.org
> >wrote:
> >
> >> Hi,
> >>
> >> I am not aware of any issues with PostAdd. Your best bet is to debug
> >> inside Cayenne DataContext.newObject(..). Specifically in BaseContext
> there
> >> is a method "injectInitialValue" that has this line at the end:
> >>
> >> // invoke callbacks
> >> getEntityResolver().getCallbackRegistry().performCallbacks(
> >> LifecycleEvent.POST_ADD,
> >> object);
> >>
> >> This is where callbacks are invoked. Please share what you find here,
> and
> >> maybe based on those clues we can unwind it further.
> >>
> >> Cheers,
> >> Andrus
> >>
> >>
> >> On Aug 3, 2012, at 9:08 AM, KM wrote:
> >>
> >>> Removed the check for the key.
> >>>
> >>> It seems that the problem is that this is not getting fired at all.
> >>> Breakpoint is not being hit. This is strange.
> >>>
> >>> I have checked for the abstract declaration in the parent class.
> Setting
> >>> this up in the modeler.
> >>>
> >>> Has anyone faced this problem before?
> >>>
> >>> Thanks
> >>> Kanwar Manish
> >>>
> >>>
> >>>
> >>> --
> >>> View this message in context:
> >>
> http://cayenne.195.n3.nabble.com/Can-default-values-be-set-in-Constructor-instead-of-setPersistenceState-tp3320047p4024479.html
> >>> Sent from the Cayenne - User mailing list archive at Nabble.com.
> >>>
> >>
> >>
>
>
Re: Can default values be set in Constructor instead of setPersistenceState()?
Posted by Andrus Adamchik <an...@objectstyle.org>.
I am an Eclipse user.. I have no NetBeans experience at all unfortunately.
But you can get the source jars matching Cayenne binary jars straight from Maven repo. Here is the one you likely need:
http://search.maven.org/remotecontent?filepath=org/apache/cayenne/cayenne-server/3.1B1/cayenne-server-3.1B1-sources.jar
Andrus
On Aug 3, 2012, at 1:16 PM, Kanwar Manish wrote:
> Thanks Andrus.
>
> I am afraid that will be a bit tough for me - for now. I am a complete Java
> and Linux noob, coming from .NET background.
>
> I tried attaching 3.1B1 source to the binaries [in Netbeans 7.2] but
> failed. I just can't figure out which source folder to attach with which
> Cayenne Jar [Client, server, tools or lifecycle].
>
> Can anybody help me out here please?
>
> Thanks
> Manish
>
>
>
> On Fri, Aug 3, 2012 at 1:28 PM, Andrus Adamchik <an...@objectstyle.org>wrote:
>
>> Hi,
>>
>> I am not aware of any issues with PostAdd. Your best bet is to debug
>> inside Cayenne DataContext.newObject(..). Specifically in BaseContext there
>> is a method "injectInitialValue" that has this line at the end:
>>
>> // invoke callbacks
>> getEntityResolver().getCallbackRegistry().performCallbacks(
>> LifecycleEvent.POST_ADD,
>> object);
>>
>> This is where callbacks are invoked. Please share what you find here, and
>> maybe based on those clues we can unwind it further.
>>
>> Cheers,
>> Andrus
>>
>>
>> On Aug 3, 2012, at 9:08 AM, KM wrote:
>>
>>> Removed the check for the key.
>>>
>>> It seems that the problem is that this is not getting fired at all.
>>> Breakpoint is not being hit. This is strange.
>>>
>>> I have checked for the abstract declaration in the parent class. Setting
>>> this up in the modeler.
>>>
>>> Has anyone faced this problem before?
>>>
>>> Thanks
>>> Kanwar Manish
>>>
>>>
>>>
>>> --
>>> View this message in context:
>> http://cayenne.195.n3.nabble.com/Can-default-values-be-set-in-Constructor-instead-of-setPersistenceState-tp3320047p4024479.html
>>> Sent from the Cayenne - User mailing list archive at Nabble.com.
>>>
>>
>>
Re: Can default values be set in Constructor instead of setPersistenceState()?
Posted by Kanwar Manish <ka...@gmail.com>.
Thanks Andrus.
I am afraid that will be a bit tough for me - for now. I am a complete Java
and Linux noob, coming from .NET background.
I tried attaching 3.1B1 source to the binaries [in Netbeans 7.2] but
failed. I just can't figure out which source folder to attach with which
Cayenne Jar [Client, server, tools or lifecycle].
Can anybody help me out here please?
Thanks
Manish
On Fri, Aug 3, 2012 at 1:28 PM, Andrus Adamchik <an...@objectstyle.org>wrote:
> Hi,
>
> I am not aware of any issues with PostAdd. Your best bet is to debug
> inside Cayenne DataContext.newObject(..). Specifically in BaseContext there
> is a method "injectInitialValue" that has this line at the end:
>
> // invoke callbacks
> getEntityResolver().getCallbackRegistry().performCallbacks(
> LifecycleEvent.POST_ADD,
> object);
>
> This is where callbacks are invoked. Please share what you find here, and
> maybe based on those clues we can unwind it further.
>
> Cheers,
> Andrus
>
>
> On Aug 3, 2012, at 9:08 AM, KM wrote:
>
> > Removed the check for the key.
> >
> > It seems that the problem is that this is not getting fired at all.
> > Breakpoint is not being hit. This is strange.
> >
> > I have checked for the abstract declaration in the parent class. Setting
> > this up in the modeler.
> >
> > Has anyone faced this problem before?
> >
> > Thanks
> > Kanwar Manish
> >
> >
> >
> > --
> > View this message in context:
> http://cayenne.195.n3.nabble.com/Can-default-values-be-set-in-Constructor-instead-of-setPersistenceState-tp3320047p4024479.html
> > Sent from the Cayenne - User mailing list archive at Nabble.com.
> >
>
>
Re: Can default values be set in Constructor instead of setPersistenceState()?
Posted by Andrus Adamchik <an...@objectstyle.org>.
Hi,
I am not aware of any issues with PostAdd. Your best bet is to debug inside Cayenne DataContext.newObject(..). Specifically in BaseContext there is a method "injectInitialValue" that has this line at the end:
// invoke callbacks
getEntityResolver().getCallbackRegistry().performCallbacks(
LifecycleEvent.POST_ADD,
object);
This is where callbacks are invoked. Please share what you find here, and maybe based on those clues we can unwind it further.
Cheers,
Andrus
On Aug 3, 2012, at 9:08 AM, KM wrote:
> Removed the check for the key.
>
> It seems that the problem is that this is not getting fired at all.
> Breakpoint is not being hit. This is strange.
>
> I have checked for the abstract declaration in the parent class. Setting
> this up in the modeler.
>
> Has anyone faced this problem before?
>
> Thanks
> Kanwar Manish
>
>
>
> --
> View this message in context: http://cayenne.195.n3.nabble.com/Can-default-values-be-set-in-Constructor-instead-of-setPersistenceState-tp3320047p4024479.html
> Sent from the Cayenne - User mailing list archive at Nabble.com.
>
Re: Can default values be set in Constructor instead of
setPersistenceState()?
Posted by KM <ka...@gmail.com>.
Removed the check for the key.
It seems that the problem is that this is not getting fired at all.
Breakpoint is not being hit. This is strange.
I have checked for the abstract declaration in the parent class. Setting
this up in the modeler.
Has anyone faced this problem before?
Thanks
Kanwar Manish
--
View this message in context: http://cayenne.195.n3.nabble.com/Can-default-values-be-set-in-Constructor-instead-of-setPersistenceState-tp3320047p4024479.html
Sent from the Cayenne - User mailing list archive at Nabble.com.
Re: Can default values be set in Constructor instead of setPersistenceState()?
Posted by Michael Gentry <mg...@masslight.net>.
Hi Kanwar,
Why are you checking for null? Just set the PK.
mrg
On Fri, Jul 27, 2012 at 4:19 AM, KM <ka...@gmail.com> 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.
Re: Can default values be set in Constructor instead of
setPersistenceState()?
Posted by KM <ka...@gmail.com>.
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.
Re: Can default values be set in Constructor instead of setPersistenceState()?
Posted by Michael Gentry <mg...@masslight.net>.
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 <jo...@essvote.com> 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)?
>
>