-->
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.  [ 1 post ] 
Author Message
 Post subject: Converting a complex HQL-query to use the Criteria API
PostPosted: Wed Jan 27, 2010 3:02 am 
Newbie

Joined: Wed Oct 01, 2008 2:19 am
Posts: 2
Hi. I'm having huge problems converting a specific HQL-query to using the Criteria API. I'll first start with my datamodel.

Code:
class User {
   ...
   @Id
   @GeneratedValue(strategy = GenerationType.AUTO)
   private Long id;

   @ManyToMany
   private Set<BusinessUnit> businessUnits;
   ...
}

class BusinessUnit {
   ...
   @ManyToOne
   private Organization organization;
   ...
}

class Organization {
   ...
}

My current HQL-query looks like this

Code:
SELECT child FROM BusinessUnit AS child
WHERE child IN (SELECT elements(u.businessUnits) FROM User AS u WHERE u.id=42)
AND organization=13


In other words, I have an id of a User entity. My query fetches all the BusinessUnits the User object has a reference to, BUT with the exception that the BusinessUnit's organization should be X. So, is it even possible to write this query with the Criteria API? Note that the Organization does not have any kind of reference to either User or BusinessUnit, and BusinessUnit does not have any reference to User. I only have a one-way relation from User to BusinessUnit. Unfortunately, changing the datamodel will not be an option.

All help is highly appreciated!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.