-->
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: Criteria question
PostPosted: Thu Feb 05, 2004 7:05 pm 
Newbie

Joined: Fri Sep 26, 2003 4:29 pm
Posts: 16
Hi,

I'm new to the Criteria API and I'm trying to write an ad-hoc query generator but failing to find the solution to a particular problem. Got to the stage where I'm not sure if it's my knowledge lacking, or it just can't be done.

I'm after instances of class x. I have two limiting criteria, say;
x.a.b.c.d = ?
x.y.z = ?

What I would like to do is combine the results of these two criteria in a logical manner (eg, d = ? AND z = ?), but I can't seem to find a way of using the api to do both the logical combining and ensuring the joins underlying the associations (x.a.b.c and x.y) are used (as implict are not supported in Criteria). I've tryed both chained createCriteria and using aliases but haven't had any success.

Before I go and implement the logical combinations in java, is there anyway I can do this directly using the Criteria API.

thanks in advance,

Jonny


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 06, 2004 1:56 am 
Expert
Expert

Joined: Fri Nov 07, 2003 4:24 am
Posts: 315
Location: Cape Town, South Africa
Have a look at the javadocs for Expression.conjunction() and Expression.disjunction().

Then have a look at the Hibernate chapter posting at http://www.theserverside.com - an example is illustrated using these methods.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 06, 2004 2:44 pm 
Newbie

Joined: Fri Sep 26, 2003 4:29 pm
Posts: 16
Thanks for the reply.

I found the chapter after I posted the message and it gave me enough examples to solve the problem. Using aliases was the key.

Can't wait to buy the book.

drj wrote:
Have a look at the javadocs for Expression.conjunction() and Expression.disjunction().

Then have a look at the Hibernate chapter posting at http://www.theserverside.com - an example is illustrated using these methods.


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.