-->
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.  [ 2 posts ] 
Author Message
 Post subject: Question on Criteria usage
PostPosted: Wed Aug 03, 2005 9:37 am 
Newbie

Joined: Thu Oct 21, 2004 2:43 pm
Posts: 9
Hi all,
taking my first steps into the deeper workings of Hibernate i come across the following problem (at least for me) :
Let's say i have three Tables in the DB ->
Child / Parents / Country
And i want to query for a child with name A and his Parents should live in Germany

but i dont know how i have to do this in Hibernate with the Criteria classes
since 1 CriteriaEntry is always for 1 Alias (Child in my case).
CriteriaEntry(alias,expression) -> in my case the expression is an AndExpression -> for both the name and the Country

the query i need to get is easy
select * from child where name = 'A' and parents in (select id from Parents where country = (select id from Country where name = 'Germany'))

how should i handle this with these Criterion and Expressions ?
anyone ?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 03, 2005 10:29 am 
Regular
Regular

Joined: Thu May 26, 2005 2:08 pm
Posts: 99
It looks like a child contains an association to a parent, and a parent contains an association to a country. Yes? It would help if you post your mappings.

If that's the case, then you're going to end up with something like this.

Code:

Criteria childCriteria = session.createCriteria(Child.class);
childCriteria.add(Expression("name", "A"));
Criteria parentCriteria = childCriteria.createCriteria("parent");
parentCriteria.createCriteria("country").add(Expression("name", "Germany"));



I'd suggest rereading section 16.4 for more info.


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