-->
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 API Help
PostPosted: Sat Sep 22, 2007 2:55 am 
Newbie

Joined: Sat Sep 22, 2007 1:48 am
Posts: 4
Hi,

I have 3 classes A,B,C and B,C having properties b1 and c1 respectively

I want to create an Equivalent of the following HQL in Criteria API.

from A where B.B1=212 or C.C1=12 : Query1

Is the above code equivalent to

Code:
      Criteria c=session.createCriteria(B.class);
      Criteria c1=c.createCriteria("b");
      Criteria c2=c.createCriteria("c");
      c1.add(Expression.eq("b1",212);
      c2.add(Expression.eq("c1",12);


I don't really know but i think the above Criteria is equivalent to

from A where B.B1=212 and C.C1=12 : Query2

if its so then what will will equivalent code for Query1,

Thanks in adv


Top
 Profile  
 
 Post subject:
PostPosted: Sun Sep 23, 2007 1:23 am 
Newbie

Joined: Wed Aug 17, 2005 3:02 pm
Posts: 7
I'm guessing B and C are both properties in A. If that is the case, your code should look like this:
Code:
Criteria criteria = session.createCriteria(A.class);
criteria.createAlias("B", "b").createAlias("C", "c")
          .add(Expression.or(Expression.eq("b.b1", 212), Expression.eq("c.c1", 12)));


Top
 Profile  
 
 Post subject:
PostPosted: Sun Sep 23, 2007 2:18 am 
Newbie

Joined: Sat Sep 22, 2007 1:48 am
Posts: 4
Thanks I have done exactly. And it works


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.