-->
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: Help with criteria for multi-level associations
PostPosted: Fri Mar 03, 2006 6:03 pm 
Newbie

Joined: Fri Mar 03, 2006 5:21 pm
Posts: 1
I'm using Hibernate 3.0 with Oracle and trying to replicate the following HQL with Criteria:

Code:
from License license
where license.server.configuration.product.id = ?
and license.user.country.id = ?


I've been trying things like this:

Code:
Criteria crit = session.createCriteria(License.class);
crit = crit.createCriteria("server").createCriteria("configuration").add(
Restrictions.eq("product.id",productId));

// the next line doesn't work because I'm already trapped in the "configuration" context..
crit = crit.createCriteria("user").add(
Restrictions.eq("country.id",countryId));


So is there anyway to navigate back "up" the object heirarchy? Or is this approach all wrong?

Also, in this particular case I think I can probably just get away with using createAlias("user") if I could put a constraint on the country_id attribute itself, without linking to the country table. Something like:

Code:
// obviously doesn't work
crit = crit.createAlias("user").add(
Restrictions.eq("country_id",countryId));


I don't really need to restrict the country object, I'm just looking at a property of the user table which happens to be a foreign key.. is there some way to do this with pure criteria or do I have to use a sqlRestriction?

Thanks!


Last edited by vahnsin on Wed Jan 15, 2014 11:29 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: Help with criteria for multi-level associations
PostPosted: Fri Mar 03, 2006 6:21 pm 
Beginner
Beginner

Joined: Thu Oct 27, 2005 11:53 am
Posts: 42
vahnsin wrote:
Code:
Criteria crit = session.createCriteria(License.class);
crit.createCriteria("server").createCriteria("configuration").add(
Restrictions.eq("product.id",productId));

crit.createCriteria("user").add(
Restrictions.eq("country.id",countryId));



this should work, dont assign crit


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.