You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cayenne.apache.org by Dave Lamy <da...@gmail.com> on 2009/06/22 04:07:17 UTC
Transient objects question
Quick question/problem on transient objects:
I've got a persistent class AppVersion, which simply tracks a version of the
code/database values for migration purposes. I want to have a persistent
AppVersion in the database, but then create a transient AppVersion
representing the code version for comparison purposes.
So I did what came naturally for the transient object (using
Cayenne-generated _AppVersion/AppVersion classes):
AppVersion codeVersion = new AppVersion();
codeVersion.setMajorNumber(1);
But I get an exception (3.0 M5):
java.lang.NullPointerException
at
org.apache.cayenne.util.ObjectContextGraphAction.handlePropertyChange(ObjectContextGraphAction.java:59)
at
org.apache.cayenne.access.DataContext.propertyChanged(DataContext.java:1591)
at
org.apache.cayenne.CayenneDataObject.writeProperty(CayenneDataObject.java:226)
...
The ObjectContextGraphAction is pulling the ObjectId, which is null in the
transient object.
What am I doing wrong here? How can I create a transient object and write
property values without getting this NPE?
Thanks for the help--
Dave
Re: Transient objects question
Posted by Dave Lamy <da...@gmail.com>.
Hey Mike--
Another day, a fresh look.. I found it, it's my fault. I have code that is
nonchalantly providing an ObjectContext to the transient object, which is
why the propertyChange event code is firing.
Thanks anyway :-).
Dave
On Mon, Jun 22, 2009 at 8:41 AM, Michael Gentry <mg...@masslight.net>wrote:
> Hi Dave,
>
> Are you getting the NPE immediately after calling:
>
> codeVersion.setMajorNumber(1);
>
> or is it further along?
>
>
> On Sun, Jun 21, 2009 at 10:07 PM, Dave Lamy<da...@gmail.com> wrote:
> > Quick question/problem on transient objects:
> >
> > I've got a persistent class AppVersion, which simply tracks a version of
> the
> > code/database values for migration purposes. I want to have a persistent
> > AppVersion in the database, but then create a transient AppVersion
> > representing the code version for comparison purposes.
> >
> > So I did what came naturally for the transient object (using
> > Cayenne-generated _AppVersion/AppVersion classes):
> >
> > AppVersion codeVersion = new AppVersion();
> > codeVersion.setMajorNumber(1);
> >
> > But I get an exception (3.0 M5):
> >
> > java.lang.NullPointerException
> > at
> >
> org.apache.cayenne.util.ObjectContextGraphAction.handlePropertyChange(ObjectContextGraphAction.java:59)
> > at
> >
> org.apache.cayenne.access.DataContext.propertyChanged(DataContext.java:1591)
> > at
> >
> org.apache.cayenne.CayenneDataObject.writeProperty(CayenneDataObject.java:226)
> > ...
> >
> > The ObjectContextGraphAction is pulling the ObjectId, which is null in
> the
> > transient object.
> >
> > What am I doing wrong here? How can I create a transient object and
> write
> > property values without getting this NPE?
> >
> > Thanks for the help--
> > Dave
> >
>
Re: Transient objects question
Posted by Michael Gentry <mg...@masslight.net>.
Hi Dave,
Are you getting the NPE immediately after calling:
codeVersion.setMajorNumber(1);
or is it further along?
On Sun, Jun 21, 2009 at 10:07 PM, Dave Lamy<da...@gmail.com> wrote:
> Quick question/problem on transient objects:
>
> I've got a persistent class AppVersion, which simply tracks a version of the
> code/database values for migration purposes. I want to have a persistent
> AppVersion in the database, but then create a transient AppVersion
> representing the code version for comparison purposes.
>
> So I did what came naturally for the transient object (using
> Cayenne-generated _AppVersion/AppVersion classes):
>
> AppVersion codeVersion = new AppVersion();
> codeVersion.setMajorNumber(1);
>
> But I get an exception (3.0 M5):
>
> java.lang.NullPointerException
> at
> org.apache.cayenne.util.ObjectContextGraphAction.handlePropertyChange(ObjectContextGraphAction.java:59)
> at
> org.apache.cayenne.access.DataContext.propertyChanged(DataContext.java:1591)
> at
> org.apache.cayenne.CayenneDataObject.writeProperty(CayenneDataObject.java:226)
> ...
>
> The ObjectContextGraphAction is pulling the ObjectId, which is null in the
> transient object.
>
> What am I doing wrong here? How can I create a transient object and write
> property values without getting this NPE?
>
> Thanks for the help--
> Dave
>