User have ManyToMany relationship with Group (owner)
Group have ManyToMany relationship with User
User contains named query:
@NamedQueries(@NamedQuery(name = "User.findByGroupRealm", queryString = "SELECT users "
+ "FROM User users "
+ "WHERE ? IN (users.groups) AND users.realm=?"))
This query was converted to
select user0_.id as id10_, user0_.name as name10_, user0_.realm as realm10_ from rights_users user0_, rights_user2group groups1_, rights_groups group2_ where user0_.id=groups1_.userid and groups1_.grp=group2_.id and (? in (.)) and user0_.realm=?
1. Construction (? in (.)) is wrong
2. Hibernate don't need to load rights_groups table, since only id of group need to be tested and it is already contains in rights_user2group table.
3. If rights_groups shuold be included to check some conditions, there is should be an option to disable this check.
Derby DB, Hibernate Annotations from CVS