When I execute the following HQL, hibernate is generating a wrong SQL instruction:
Code:
1. StringBuffer hql = new StringBuffer();
2. hql.append(" select gau.id ");
3. hql.append(" from GroupAndUser as gau ");
4. hql.append(" ,GroupAuthorization as auth ");
5. hql.append(" where ");
6. hql.append(" gau.user.id = :userKey ");
7. hql.append(" and auth.userGroup = gau.group ");
8. hql.append(" and ( ");
9. hql.append(" ( ");
10. hql.append(" auth.classKey = :classKey ");
11. hql.append(" and auth.permissionString like :permissionString ");
12. hql.append(" ) ");
13. hql.append(" or gau.group.admin = true ");
14. hql.append(" ) ");
15.
16. Session sess = PersistenceUtil.getSession(database);
17. sess.beginTransaction();
18.
19. try {
20. Query query = sess.createQuery(hql.toString());
21. query.setParameter("userKey", userKey);
22. query.setParameter("classKey", classKey);
23. query.setParameter("permissionString", "%" + permission + "%");
24.
25. return query.uniqueResult() != null;
26. } finally {
27. sess.getTransaction().rollback();
28. }
and (
groupautho1_.classKey=?
and (
groupautho1_.permissionString like ?
)
or usergroup2_.admin=true
)
Generated SQL:
Code:
select
groupandus0_.id as col_0_0_
from
SYSPERMISSION groupandus0_,
SYSPERMISSION groupautho1_,
SYSUSER usergroup2_
where
groupandus0_.groupid=usergroup2_.id
and groupandus0_.userid=?
and groupautho1_.groupid=groupandus0_.groupid
and (
groupautho1_.classKey=?
and (
groupautho1_.permissionString like ?
)
or usergroup2_.admin=true
)
Any idea why Hibernate is generating a wrong where clause? I already tried to switch the order and still gettong the wrong SQL.
Any help would really be appreciatted.
Thanks.