-->
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.  [ 3 posts ] 
Author Message
 Post subject: HQL for NULL associations
PostPosted: Thu Jan 27, 2005 6:41 pm 
Newbie

Joined: Tue Sep 21, 2004 5:42 pm
Posts: 2
Using Hibernate 2.1.4. Sorry if this has been posted before, but I did several searches and could not quite come up with what I needed.

I have a object with a recursive structure. The object has a parent-child association to itself expressed as (0..1 --> 0..*).

Now, I want to retrieve the top level objects in this structure by selecting all objects that have no parent. In SQL, it would be "SELECT * FROM Object WHERE PARENT_ID = NULL".

What is the corresponding HQL for checking to see if an association is NULL??


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 27, 2005 8:41 pm 
Senior
Senior

Joined: Sun Oct 26, 2003 5:05 am
Posts: 139
Actually, your select statement would not work. It's really:

Code:
SELECT * FROM Object WHERE PARENT_ID [b]IS[/b] NULL


Consequently, the HQL is basically the same thing...

Code:
select object from Object object where object.parent.id is null


Since HQL is an object language, you can just refer to the object reference and Hibernate will know you really mean the ID, like this:

Code:
select object from Object object where [b]object.parent[/b] is null


I suggest reading the docs since this isn't that hard...


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 27, 2005 8:42 pm 
Senior
Senior

Joined: Sun Oct 26, 2003 5:05 am
Posts: 139
The b and /b were meant to bold things. I guess that doesn't work using the code tags.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.