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!