JPQL join fails to load related entity

Hi guys.
I am having some trouble with getting the related entity using JPQL query.
For example when I am trying getting User roles using this query:


 UserRole> existingUserRoles = dataService.loadList(LoadContext.create(UserRole.class)
       .setQuery(LoadContext.createQuery("select ur from sec$UserRole ur join fetch ur.role where ur.user.login = :user_login")
                                                .setParameter("user_login", user.getLogin()))
   );

it fails to load the UserRole.role field and accessing it throws an java.lang.IllegalStateException: Cannot get unfetched attribute [role] from detached object com.haulmont.cuba.security.entity.UserRole.

I have also tried different forms of join, based on JPQL documentation but still got the same result.
What is the proper way of doing this?

Hi Alexandru,

The proper way of loading graphs of objects is using views. You can see examples of using views in quick start and other sample projects.