I am using Spring Data
and defining following query:
@Query("SELECT u FROM AppUser u LEFT OUTER JOIN fetch u.userRights a LEFT OUTER JOIN fetch u.userGroups g LEFT OUTER JOIN fetch u.userGroups ug LEFT OUTER JOIN FETCH ug.groupRights where u.login = :login")
public Optional<AppUser> findOneWithCompleteRights(@Param("login") String login);
As you might see, I want to get back the logged in user with all his access rights. While starting the spring application, it runs into:
Caused by: javax.persistence.PersistenceException: org.hibernate.loader.MultipleBagFetchException: cannot simultaneously fetch multiple bags
I have checked following: Multiple fetches with EAGER type in Hibernate with JPA
If I change all@XXXToMany
Types to java.util.Set
, it works, but I would like to decide the type on my own...
The other annotations of linked solution (see bottom) seem to be ignored if attached to the @Query
method. Second would not make sense, anyway.
- Load each collection separately using subselect
@Fetch(FetchMode.SELECT)
- Force usage of list instead of bag by adding index column
@IndexColumn(name="LIST_INDEX")
Does anybody have another solution rather than setting the type to Set
?