0

I am trying to mimic a eager fetch for a specific situation only.I use spring-data-jpa with hibernate 4.1 as implementation. i have User, Role and Right. Role and User have many-to-many with additional field thus mapped as an Entity RoleUser. Role and Right also are in many-to-many mapped as an Entity RoleRight.

I would like to load all right and role for a user into the Authorization mechanism of the application when needed. this query below is giving illegal attempt to dereference collection

   List<Role> roles = (List<Role>)em.createQuery("select r from RoleImpl r JOIN FETCH r.roleRightMap rrm JOIN FETCH rrm.right ur WHERE r.userRoleMap.user.ID=:id ")
            .setParameter("id", ID).getResultList();

How can it be rewritten to load the role and its mapping thanks.

4

1 回答 1

0

对不起,没关系。这是一个疏忽。

查询应该是这样的:

select r from RoleImpl r LEFT JOIN FETCH r.roleRightMap rrm LEFT JOIN FETCH r.userRoleMap urm WHERE urm.user.ID=:id 
于 2012-11-04T19:21:24.070 回答