Friday, April 8, 2011

How do I write a HQL Query for this?

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
{
...
}
From stackoverflow
  • 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.

0 comments:

Post a Comment