-->
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.  [ 6 posts ] 
Author Message
 Post subject: query question
PostPosted: Tue Apr 27, 2004 2:38 pm 
Beginner
Beginner

Joined: Mon Jan 12, 2004 3:39 pm
Posts: 23
I have and object c and it has a collection of a. I need a query to returns all instances of c who have the a colletion empty.

In SQL I would write something like this:

select c.* from c , a
where c.id= a.fk_id(+)
and a.id is null

How do I write it in HQL?

I tried using having count(a) =0 but I was returned the error message : path expression ends in a composite value

Can anyone help me?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 27, 2004 3:16 pm 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
i'm not sure but i think id is a protected name

c.id

try to replace id with another name (need some rework)

and i repeat i'm not sure, i may be wrong


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 27, 2004 3:22 pm 
Beginner
Beginner

Joined: Mon Jan 12, 2004 3:39 pm
Posts: 23
that is not the name of the field/property it is only to illustrate the case


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 27, 2004 6:52 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
From the docs:

Code:
from eg.Cat cat where exists elements(cat.kittens)


There might be more efficient ways though.

BTW: What kind of freaky sql syntax is that? That should be an outer join I suppose?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 27, 2004 10:40 pm 
Beginner
Beginner

Joined: Mon Jan 12, 2004 3:39 pm
Posts: 23
I'm debuging the application and Hibernate's SQL bothers me.

It seems that after it executes the statements that produce the results, it also runs lots of other "selects" in different tables. I don't know why it does that all I know is my DBA wants me dead.

Do you know what is the most efficient to implement this query?


PS: The previous SQL is Oracle's outer join. I wasn't familiar with that sintax until recently :)


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 28, 2004 6:57 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Enable lazy fetching or outer join fetching for associations, use join fetch in HQL, read the docs.


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