You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cayenne.apache.org by Marcin Skladaniec <ma...@ish.com.au> on 2007/02/28 01:49:34 UTC

expression to find out null relationship

Hi

I have a simple one-to-many relationship : AppleTree - Apple. I'm  
doing a query :
new SelectQuery(AppleTree.class, expression)
how should the expression look like to return the trees with apples ?
expression = ExpressionFactory.noMatchExp(AppleTree.APPLES, null)  
does not seem to work, neither does
expression = ExpressionFactory.noMatchExp("applesArray", null)

Regards
Marcin

Re: expression to find out null relationship

Posted by Marcin Skladaniec <ma...@ish.com.au>.
On 04/03/2007, at 1:22 AM, Mike Kienenberger wrote:

> For your first case, be sure that $select also returns a field  
> named id.
It does return id. The response contains the joined tables AppleTree  
and Apple, and $select has only the AppleTree fields listed:  
AppleTree.id, AppleTree.height etc. Still the object is not faulted  
and the exception is produced.
>
> For your second case, you have rooted your query on AppleTree, but you
> are basing your query as if you were rooted on Apple.  Provide a path
> from AppleTree to Apple.
>
> SelectQuery sq = new SelectQuery(AppleTree.class,
> ExpressionFactory.matchExp(AppleTree.APPLES + "." + Apple.COLOR,
> "red") );
Yes, I'm doing that, I wrote it not correctly in the message only, as  
the real life example is far more complex than the Apple/AppleTree  
model.
Anyway the Expression does not affect the result.
Regards
Marcin
>
> On 3/3/07, Marcin Skladaniec <ma...@ish.com.au> wrote:
>> Hi
>> I'm still struggling trying to fetch only AppleTrees with Apples
>> which are red.
>>
>> Apple -AppleTree is a simple many-to-one relationship. I dont want to
>> fault every appleTree and apple, I want to use either NamedQuery or
>> Expression.
>> When I attempt with NamedQuery like:
>> <sql><![CDATA[SELECT $select FROM AppleTree join Apple on
>> (AppleTree.id = Apple.treeId) where (Apple.color = 'red') ]]></sql>
>> I get a correct sql response, but cayenne fails to build up the
>> entities out of it:
>> org.apache.cayenne.CayenneRuntimeException: [v.3.0-SNAPSHOT Jan 19
>> 2007 05:26:38] Remote error. URL - http://localhost:8181/angel- 
>> server-
>> cayenne; CAUSE - [v.3.0-SNAPSHOT Jan 19 2007 05:26:38] [v.3.0-
>> SNAPSHOT Jan 19 2007 05:26:38] Exception processing message
>> org.apache.cayenne.remote.QueryMessage. Root cause: [v.3.0-SNAPSHOT
>> Jan 19 2007 05:26:38] Null value for 'id'.
>>
>> when I try with Expression the expression is ignored and makes no
>> difference, (is there an automatic join clause created ?):
>> SelectQuery sq = new SelectQuery(AppleTree.class,
>> ExpressionFactory.matchExp(Apple.COLOR, "red") );
>>
>> Does someone have any hints ?
>> Marcin
>>
>>
>>
>> On 01/03/2007, at 12:48 AM, Mike Kienenberger wrote:
>>
>> > You may be right.  I vaguely recall now that this only works for
>> > to-one relations.   For to-many relations, I can't remember how I
>> > handled this.
>> >
>> >
>> > On 2/28/07, Marcin Skladaniec <ma...@ish.com.au> wrote:
>> >> Hi
>> >> Mike, the ExpressionFactory.noMatchExp(AppleTree.APPLE_PROPERTY,
>> >> null) does not work. I tried. I recollect I used Expression which
>> >> aimed other way around (from many to one, example :
>> >> ExpressionFactory.noMatchExp(Apple.APPLE_TREE_PROPERTY, null) ).
>> >> Marcin
>> >>
>> >>
>> >> On 28/02/2007, at 11:11 AM, Mike Kienenberger wrote:
>> >>
>> >> > ExpressionFactory.noMatchExp(AppleTree.APPLE_PROPERTY, null)
>> >> >
>> >> > Be aware that you cannot safely combine this expression with  
>> other
>> >> > expressions due to outer join issues, unless you're using the  
>> outer
>> >> > join patch.   I think there was another null-related fix  
>> mixed into
>> >> > that patch.
>> >> >
>> >> > On 2/27/07, Marcin Skladaniec <ma...@ish.com.au> wrote:
>> >> >> Hi
>> >> >>
>> >> >> I have a simple one-to-many relationship : AppleTree -  
>> Apple. I'm
>> >> >> doing a query :
>> >> >> new SelectQuery(AppleTree.class, expression)
>> >> >> how should the expression look like to return the trees with
>> >> apples ?
>> >> >> expression = ExpressionFactory.noMatchExp(AppleTree.APPLES,  
>> null)
>> >> >> does not seem to work, neither does
>> >> >> expression = ExpressionFactory.noMatchExp("applesArray", null)
>> >> >>
>> >> >> Regards
>> >> >> Marcin
>> >> >>
>> >>
>> >> Marcin
>> >>
>> >>
>> >>
>> >>
>>
>> Marcin
>>
>>
>>
>>

Marcin




Re: expression to find out null relationship

Posted by Mike Kienenberger <mk...@gmail.com>.
For your first case, be sure that $select also returns a field named id.

For your second case, you have rooted your query on AppleTree, but you
are basing your query as if you were rooted on Apple.  Provide a path
from AppleTree to Apple.

SelectQuery sq = new SelectQuery(AppleTree.class,
ExpressionFactory.matchExp(AppleTree.APPLES + "." + Apple.COLOR,
"red") );

On 3/3/07, Marcin Skladaniec <ma...@ish.com.au> wrote:
> Hi
> I'm still struggling trying to fetch only AppleTrees with Apples
> which are red.
>
> Apple -AppleTree is a simple many-to-one relationship. I dont want to
> fault every appleTree and apple, I want to use either NamedQuery or
> Expression.
> When I attempt with NamedQuery like:
> <sql><![CDATA[SELECT $select FROM AppleTree join Apple on
> (AppleTree.id = Apple.treeId) where (Apple.color = 'red') ]]></sql>
> I get a correct sql response, but cayenne fails to build up the
> entities out of it:
> org.apache.cayenne.CayenneRuntimeException: [v.3.0-SNAPSHOT Jan 19
> 2007 05:26:38] Remote error. URL - http://localhost:8181/angel-server-
> cayenne; CAUSE - [v.3.0-SNAPSHOT Jan 19 2007 05:26:38] [v.3.0-
> SNAPSHOT Jan 19 2007 05:26:38] Exception processing message
> org.apache.cayenne.remote.QueryMessage. Root cause: [v.3.0-SNAPSHOT
> Jan 19 2007 05:26:38] Null value for 'id'.
>
> when I try with Expression the expression is ignored and makes no
> difference, (is there an automatic join clause created ?):
> SelectQuery sq = new SelectQuery(AppleTree.class,
> ExpressionFactory.matchExp(Apple.COLOR, "red") );
>
> Does someone have any hints ?
> Marcin
>
>
>
> On 01/03/2007, at 12:48 AM, Mike Kienenberger wrote:
>
> > You may be right.  I vaguely recall now that this only works for
> > to-one relations.   For to-many relations, I can't remember how I
> > handled this.
> >
> >
> > On 2/28/07, Marcin Skladaniec <ma...@ish.com.au> wrote:
> >> Hi
> >> Mike, the ExpressionFactory.noMatchExp(AppleTree.APPLE_PROPERTY,
> >> null) does not work. I tried. I recollect I used Expression which
> >> aimed other way around (from many to one, example :
> >> ExpressionFactory.noMatchExp(Apple.APPLE_TREE_PROPERTY, null) ).
> >> Marcin
> >>
> >>
> >> On 28/02/2007, at 11:11 AM, Mike Kienenberger wrote:
> >>
> >> > ExpressionFactory.noMatchExp(AppleTree.APPLE_PROPERTY, null)
> >> >
> >> > Be aware that you cannot safely combine this expression with other
> >> > expressions due to outer join issues, unless you're using the outer
> >> > join patch.   I think there was another null-related fix mixed into
> >> > that patch.
> >> >
> >> > On 2/27/07, Marcin Skladaniec <ma...@ish.com.au> wrote:
> >> >> Hi
> >> >>
> >> >> I have a simple one-to-many relationship : AppleTree - Apple. I'm
> >> >> doing a query :
> >> >> new SelectQuery(AppleTree.class, expression)
> >> >> how should the expression look like to return the trees with
> >> apples ?
> >> >> expression = ExpressionFactory.noMatchExp(AppleTree.APPLES, null)
> >> >> does not seem to work, neither does
> >> >> expression = ExpressionFactory.noMatchExp("applesArray", null)
> >> >>
> >> >> Regards
> >> >> Marcin
> >> >>
> >>
> >> Marcin
> >>
> >>
> >>
> >>
>
> Marcin
>
>
>
>

Re: expression to find out null relationship

Posted by Andrus Adamchik <an...@objectstyle.org>.
On Mar 3, 2007, at 7:47 AM, Marcin Skladaniec wrote:

> - [v.3.0-SNAPSHOT Jan 19 2007 05:26:38] [v.3.0-SNAPSHOT Jan 19 2007  
> 05:26:38] Exception processing message  
> org.apache.cayenne.remote.QueryMessage. Root cause: [v.3.0-SNAPSHOT  
> Jan 19 2007 05:26:38] Null value for 'id'.

Marcin,

can you print the actual DataRow before converting it to object -  
this may give you hints as to why the exception is thrown. Mike  
already mentioned that - the column naming in the response may be the  
key.

Andrus


Re: expression to find out null relationship

Posted by Marcin Skladaniec <ma...@ish.com.au>.
Hi
I'm still struggling trying to fetch only AppleTrees with Apples  
which are red.

Apple -AppleTree is a simple many-to-one relationship. I dont want to  
fault every appleTree and apple, I want to use either NamedQuery or  
Expression.
When I attempt with NamedQuery like:
<sql><![CDATA[SELECT $select FROM AppleTree join Apple on  
(AppleTree.id = Apple.treeId) where (Apple.color = 'red') ]]></sql>
I get a correct sql response, but cayenne fails to build up the  
entities out of it:
org.apache.cayenne.CayenneRuntimeException: [v.3.0-SNAPSHOT Jan 19  
2007 05:26:38] Remote error. URL - http://localhost:8181/angel-server- 
cayenne; CAUSE - [v.3.0-SNAPSHOT Jan 19 2007 05:26:38] [v.3.0- 
SNAPSHOT Jan 19 2007 05:26:38] Exception processing message  
org.apache.cayenne.remote.QueryMessage. Root cause: [v.3.0-SNAPSHOT  
Jan 19 2007 05:26:38] Null value for 'id'.

when I try with Expression the expression is ignored and makes no  
difference, (is there an automatic join clause created ?):
SelectQuery sq = new SelectQuery(AppleTree.class,  
ExpressionFactory.matchExp(Apple.COLOR, "red") );

Does someone have any hints ?
Marcin



On 01/03/2007, at 12:48 AM, Mike Kienenberger wrote:

> You may be right.  I vaguely recall now that this only works for
> to-one relations.   For to-many relations, I can't remember how I
> handled this.
>
>
> On 2/28/07, Marcin Skladaniec <ma...@ish.com.au> wrote:
>> Hi
>> Mike, the ExpressionFactory.noMatchExp(AppleTree.APPLE_PROPERTY,
>> null) does not work. I tried. I recollect I used Expression which
>> aimed other way around (from many to one, example :
>> ExpressionFactory.noMatchExp(Apple.APPLE_TREE_PROPERTY, null) ).
>> Marcin
>>
>>
>> On 28/02/2007, at 11:11 AM, Mike Kienenberger wrote:
>>
>> > ExpressionFactory.noMatchExp(AppleTree.APPLE_PROPERTY, null)
>> >
>> > Be aware that you cannot safely combine this expression with other
>> > expressions due to outer join issues, unless you're using the outer
>> > join patch.   I think there was another null-related fix mixed into
>> > that patch.
>> >
>> > On 2/27/07, Marcin Skladaniec <ma...@ish.com.au> wrote:
>> >> Hi
>> >>
>> >> I have a simple one-to-many relationship : AppleTree - Apple. I'm
>> >> doing a query :
>> >> new SelectQuery(AppleTree.class, expression)
>> >> how should the expression look like to return the trees with  
>> apples ?
>> >> expression = ExpressionFactory.noMatchExp(AppleTree.APPLES, null)
>> >> does not seem to work, neither does
>> >> expression = ExpressionFactory.noMatchExp("applesArray", null)
>> >>
>> >> Regards
>> >> Marcin
>> >>
>>
>> Marcin
>>
>>
>>
>>

Marcin




Re: expression to find out null relationship

Posted by Mike Kienenberger <mk...@gmail.com>.
You may be right.  I vaguely recall now that this only works for
to-one relations.   For to-many relations, I can't remember how I
handled this.


On 2/28/07, Marcin Skladaniec <ma...@ish.com.au> wrote:
> Hi
> Mike, the ExpressionFactory.noMatchExp(AppleTree.APPLE_PROPERTY,
> null) does not work. I tried. I recollect I used Expression which
> aimed other way around (from many to one, example :
> ExpressionFactory.noMatchExp(Apple.APPLE_TREE_PROPERTY, null) ).
> Marcin
>
>
> On 28/02/2007, at 11:11 AM, Mike Kienenberger wrote:
>
> > ExpressionFactory.noMatchExp(AppleTree.APPLE_PROPERTY, null)
> >
> > Be aware that you cannot safely combine this expression with other
> > expressions due to outer join issues, unless you're using the outer
> > join patch.   I think there was another null-related fix mixed into
> > that patch.
> >
> > On 2/27/07, Marcin Skladaniec <ma...@ish.com.au> wrote:
> >> Hi
> >>
> >> I have a simple one-to-many relationship : AppleTree - Apple. I'm
> >> doing a query :
> >> new SelectQuery(AppleTree.class, expression)
> >> how should the expression look like to return the trees with apples ?
> >> expression = ExpressionFactory.noMatchExp(AppleTree.APPLES, null)
> >> does not seem to work, neither does
> >> expression = ExpressionFactory.noMatchExp("applesArray", null)
> >>
> >> Regards
> >> Marcin
> >>
>
> Marcin
>
>
>
>

Re: expression to find out null relationship

Posted by Marcin Skladaniec <ma...@ish.com.au>.
Hi
Mike, the ExpressionFactory.noMatchExp(AppleTree.APPLE_PROPERTY,  
null) does not work. I tried. I recollect I used Expression which  
aimed other way around (from many to one, example :  
ExpressionFactory.noMatchExp(Apple.APPLE_TREE_PROPERTY, null) ).
Marcin


On 28/02/2007, at 11:11 AM, Mike Kienenberger wrote:

> ExpressionFactory.noMatchExp(AppleTree.APPLE_PROPERTY, null)
>
> Be aware that you cannot safely combine this expression with other
> expressions due to outer join issues, unless you're using the outer
> join patch.   I think there was another null-related fix mixed into
> that patch.
>
> On 2/27/07, Marcin Skladaniec <ma...@ish.com.au> wrote:
>> Hi
>>
>> I have a simple one-to-many relationship : AppleTree - Apple. I'm
>> doing a query :
>> new SelectQuery(AppleTree.class, expression)
>> how should the expression look like to return the trees with apples ?
>> expression = ExpressionFactory.noMatchExp(AppleTree.APPLES, null)
>> does not seem to work, neither does
>> expression = ExpressionFactory.noMatchExp("applesArray", null)
>>
>> Regards
>> Marcin
>>

Marcin




Re: expression to find out null relationship

Posted by Mike Kienenberger <mk...@gmail.com>.
ExpressionFactory.noMatchExp(AppleTree.APPLE_PROPERTY, null)

Be aware that you cannot safely combine this expression with other
expressions due to outer join issues, unless you're using the outer
join patch.   I think there was another null-related fix mixed into
that patch.

On 2/27/07, Marcin Skladaniec <ma...@ish.com.au> wrote:
> Hi
>
> I have a simple one-to-many relationship : AppleTree - Apple. I'm
> doing a query :
> new SelectQuery(AppleTree.class, expression)
> how should the expression look like to return the trees with apples ?
> expression = ExpressionFactory.noMatchExp(AppleTree.APPLES, null)
> does not seem to work, neither does
> expression = ExpressionFactory.noMatchExp("applesArray", null)
>
> Regards
> Marcin
>