Using Hibernate 3.2.5
We have entities User, Role, Group. The User class has a Map of Roles to sets of Groups. Since the value class of a map must be a mapped entity itself, we created another mapped entity "GroupSet".
class User {
private Map<Role,GroupSet> groups;
}
class GroupSet {
private Set<Group> groups;
}
So now - how to find the users for a given group? These relationships are unidirectional (User -> groups, GroupSet -> groups). So we're going to do an HQL query:
public List<User> getGroupMembers(Group group, Role role) {
String hql =
"from User user where ? in elements(user.groups[?].groups)";
return getHibernateTemplate().find(hql, new Object[] {group, role });
}
Very nice! Except it doesn't work :( Evidently the HQL parser cannot handle the above:
org.hibernate.hql.ast.QuerySyntaxException: expecting CLOSE, found '[' near line 1, column 78 [from User user where ? in elements(user.groups[?].groups)]
Now I know this expression is being interpreted correctly, I can do things like this:
"from User user where user.groups[?].groups.size > 1"
and that runs just fine...
So - is this a bug in Hibernate? Shouldn't I be able to pass the elements function an expression like user.groups[?].groups ??
If not, what is the work-around here?
Kind regards :)
Ossie
|