views:

172

answers:

1

I want a single HQL query that returns all groups containing a given user that where created before a given date. Somehow I can't get it right.

public class Group
{
    @ManyToMany
    Set<User> users;
    Date created;
}

public class User
{
...
}
A: 

II-Bhima's answer is essentially right - here is a little fix:

select g from Group as g
inner join g.users as user
where g.created < :createdDate
and user = :user

you need it so that Groups are returned and not Object[] with Group-User 2-tuples.

flybywire