-->
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.  [ 5 posts ] 
Author Message
 Post subject: Convert from HQL to Criteria API
PostPosted: Thu Jul 31, 2008 6:22 am 
Newbie

Joined: Thu Jul 31, 2008 6:16 am
Posts: 2
Is it possible to describe this HQL query:

Code:
select f from Foo f, Bar b where f.id = b.id and b.active = 0


using Criteria API? There is no association between Foo and Bar entities.

I prefer to use Criteria because it gives (IMO) more elegant code if query building involves many condition...


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 31, 2008 7:55 am 
Newbie

Joined: Thu Jul 17, 2008 2:35 am
Posts: 5
That is a perfect HQL query and you can execute it.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 31, 2008 7:55 am 
Newbie

Joined: Thu Jul 17, 2008 2:35 am
Posts: 5
That is a perfect HQL query and you can execute it.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 31, 2008 11:45 am 
Newbie

Joined: Thu Jul 31, 2008 6:16 am
Posts: 2
Erm... I know that this is a perfect HQL query. ;-)

I just want to know if it is possible to convert it to Criteria API


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 04, 2008 4:31 am 
Newbie

Joined: Wed Sep 03, 2008 7:20 am
Posts: 3
Code:
select f from Foo f, Bar b where f.id = b.id and b.active = 0


I think you can express it this way...


Code:
getSession().createCriteria(Foo.class)
                            .createCriteria("bar")
                            .add(Restrictions.eq("active",0)
                            .setFetchMode("bar",FetchMode.JOIN)


I suppose that Bar has an association with Foo and you mapped it in a property called "bar", and "id" is a JoinColumn...

Maybe I supposed too much... [/code]


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