-->
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.  [ 4 posts ] 
Author Message
 Post subject: Searching in sub-child collections
PostPosted: Wed Apr 18, 2007 7:53 am 
Newbie

Joined: Mon Jan 22, 2007 10:16 am
Posts: 5
Hello!

I'm stuck on this kind of a rough problem.
Suppose, I have a collection called aItems, which consist of objects each having a collection of bItems. Like a grandmother and grandchildren relation really.

So, I can search aItems by querying (HQL):

from sometable as st where st.aItems.name = somevalue


However, would like to do something like:

from sometable as st where st.aItems.bItems.name = somevalue

Any way to do it through HQL?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 18, 2007 12:11 pm 
Regular
Regular

Joined: Thu Dec 22, 2005 7:47 am
Posts: 62
Location: Czech Republic
add another join?

Code:
from sometable as st
join st.aItems as ait
join ait.bItems as bit
where bit.name = somevalue


this will work only if st, ait and bit are different classes. Is there a hierarchy in st, ait, bit (ie. composite) -- based on your example with grandmo i would say so? -- in such a case i woul prefer Java to search such a recursive structure.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 19, 2007 2:14 am 
Newbie

Joined: Mon Jan 22, 2007 10:16 am
Posts: 5
Ok, it turns out, my problem is a little bit more complicated.
I looked into Criteria implementation, and it seems to be the solution to my problem. However, not entirely..

Using criterias, I could do the search that I wanted in the first post:
Code:
final Criteria crit = session.createCriteria(sometable.class);
final Criteria aItems = crit.createCriteria("aItems");
final Criteria bItems = aItems.createCriteria("bItems");
bItems.add(Restrictions.like("name", "somename"));


Now, each bItem has a field cItem which is an Abstract type.
I wanted to find all sometable items that have a cItem matching the search criteria, so I made this criteria:
Code:
final Criteria crit = session.createCriteria(sometable.class);
final Criteria aItems = crit.createCriteria("aItems");
final Criteria bItems = aItems.createCriteria("bItems");
final Criteria cItems = bItems.createCriteria("cItems");
cItems.add(Restrictions.like("name", "somename"));

This fails with the error message like:
Code:
WARN 08:04:59,291 JDBCExceptionReporter SQL Error: 4104, SQLState: S0001
ERROR 08:04:59,291 JDBCExceptionReporter The multi-part identifier "cItems3_1_.Name" could not be bound.


Any ideas?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 19, 2007 2:37 am 
Regular
Regular

Joined: Thu Dec 22, 2005 7:47 am
Posts: 62
Location: Czech Republic
well, the criteria you use is simillar to my hql query.

Quote:
WARN 08:04:59,291 JDBCExceptionReporter SQL Error: 4104, SQLState: S0001
ERROR 08:04:59,291 JDBCExceptionReporter The multi-part identifier "cItems3_1_.Name" could not be bound.


no ideas untill i see your mapping, at least for the cItems.


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