Take the 2-minute tour ×

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.

share|improve this question
add comment

1 Answer

Sorry, Never mind. it was an oversight.

The query should have been like this :

select r from RoleImpl r LEFT JOIN FETCH r.roleRightMap rrm LEFT JOIN FETCH r.userRoleMap urm WHERE urm.user.ID=:id 
share|improve this answer
add comment

Your Answer


