-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 
Author Message
 Post subject: is null Expression
PostPosted: Thu Aug 31, 2006 1:41 pm 
Newbie

Joined: Sun May 07, 2006 4:36 pm
Posts: 4
The "is null" expression in HQL is not working properly if the Property in the expression is a relationship to other object. If the property in the expression is just a column in database, the "is null" expression is working. Do you guys have any experience in this matter? Is there any workaround?

Thanks,


Top
 Profile  
 
 Post subject: Re: is null Expression
PostPosted: Fri Sep 01, 2006 3:21 am 
Beginner
Beginner

Joined: Wed Aug 03, 2005 8:06 am
Posts: 40
Location: Netherlands
Hi Sjava,

Can you show us your code? When I do this:

Code:
IQuery q = session.CreateQuery("from Child c where c.Parent is null");
IList result = (ArrayList)q.List();


it works just fine. (Where session, of course, is an ISession).


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 21, 2006 5:23 pm 
Newbie

Joined: Sun May 07, 2006 4:36 pm
Posts: 4
"is null" expression doesn't work only if the property in the expression has one-to-one relationship. It works just fine for property with one-to-many relationship.

Gear, I think the objects you've shown (Parent & Child) has one-to-many and "is null" does work on that case.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 22, 2006 1:29 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
When you are accessing the property, NHibernate uses inner join implicitly. To use left join, you have to specify it explicitly in the query:
Code:
from One one left join one.ToOne toOne where toOne is null


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 22, 2006 12:50 pm 
Newbie

Joined: Sun May 07, 2006 4:36 pm
Posts: 4
Thanks sergey! That solves my problem. This explanation will be helpful in documentation. To return one type of object collection I use this query
Code:
select one from One one left join one.ToOne toOne where toOne is null


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.