You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cayenne.apache.org by Andrew Lindesay <ap...@lindesay.co.nz> on 2010/02/07 11:21:33 UTC
ObjectIdQuery Question
Hello;
I am using 3.1 snapshot and am trying to do this in order to get an DataObject instance for the ObjectId which I have;
DataContext dc = new DataContext();
ObjectId xyzObjectId = xyzObjectIds.get(i);
XYZ xyz = (XYZ) dc.performQuery(new ObjectIdQuery(xyzObjectId)).get(0);
I get an NPE here;
org.apache.cayenne.util.ObjectContextQueryAction.runQuery(ObjectContextQueryAction.java:335) at org.apache.cayenne.util.ObjectContextQueryAction.execute(ObjectContextQueryAction.java:96) at org.apache.cayenne.access.DataContext.onQuery(DataContext.java:1049) at org.apache.cayenne.access.DataContext.performQuery(DataContext.java:1038)
Which is this in code;
protected void runQuery()
{ this.response = actingContext.getChannel().onQuery(actingContext, query); }
The problem is that there is no channel on the context.
Am I using the API correctly?
Regards;
___
Andrew Lindesay
www.lindesay.co.nz
Re: ObjectIdQuery Question
Posted by Andrew Lindesay <ap...@lindesay.co.nz>.
Hello Andrey;
That's great thanks for the help; it was simply that!
cheers.
> DataContext should be created via DataContext.createDataContext() if you're
> using shared configuration (cayenne.xml in classpath). Although there could
> be changes in 3.1 shapshot - I think Andrus iы reworking something there.
> Also the simplest way to get DataObject for PK is Cayenne.objectForPk(...)
> in 3.1 and DataObjectUtils.objectForPk(...) in 3.0
___
Andrew Lindesay
www.lindesay.co.nz
Re: ObjectIdQuery Question
Posted by Andrey Razumovsky <ra...@gmail.com>.
DataContext should be created via DataContext.createDataContext() if you're
using shared configuration (cayenne.xml in classpath). Although there could
be changes in 3.1 shapshot - I think Andrus iы reworking something there.
Also the simplest way to get DataObject for PK is Cayenne.objectForPk(...)
in 3.1 and DataObjectUtils.objectForPk(...) in 3.0
2010/2/7 Andrew Lindesay <ap...@lindesay.co.nz>
> Hello;
>
> I am using 3.1 snapshot and am trying to do this in order to get an
> DataObject instance for the ObjectId which I have;
>
> DataContext dc = new DataContext();
> ObjectId xyzObjectId = xyzObjectIds.get(i);
> XYZ xyz = (XYZ) dc.performQuery(new
> ObjectIdQuery(xyzObjectId)).get(0);
>
> I get an NPE here;
>
>
> org.apache.cayenne.util.ObjectContextQueryAction.runQuery(ObjectContextQueryAction.java:335)
> at
> org.apache.cayenne.util.ObjectContextQueryAction.execute(ObjectContextQueryAction.java:96)
> at
> org.apache.cayenne.access.DataContext.onQuery(DataContext.java:1049) at
>
> org.apache.cayenne.access.DataContext.performQuery(DataContext.java:1038)
>
> Which is this in code;
>
> protected void runQuery()
> { this.response = actingContext.getChannel().onQuery(actingContext,
> query); }
>
> The problem is that there is no channel on the context.
>
> Am I using the API correctly?
>
> Regards;
>
> ___
> Andrew Lindesay
> www.lindesay.co.nz
>
>
--
Andrey