-->
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: Two Class Criteria
PostPosted: Mon Jul 03, 2006 11:53 am 
Newbie

Joined: Fri Jun 09, 2006 8:03 am
Posts: 12
Hibernate version: 3.0

I am trying to convert my HQL to criteria to better dynamically create the queries. However I ran into a problem when doing this HQL Statement:

select distinct o.id, o.order from User u, OrgUnit o where...[simple restrictions]...and u.id = o.id;

OrgUnit is distinct from User so no association is in the mapping files.

First how do I create a criteria object using both UserOrg.class and OrgUnit.class. Second, i assume you just alias these instances but how do you add the restriction of u.id = o.id. Third, how is distinct done in criteria.

Thanks for the help


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 03, 2006 6:04 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
Have you read up on DetachedCriteria? That's your only option if you must use Criteria. You'll end up with subselects, which are necessarily less efficient. If you don't have to dynamically create this query, I recommend sticking with HQL. It's better for dealing with unmapped associations.

_________________
Code tags are your friend. Know them and use them.


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.