I have manyToMany
association between User
and Role
objects ( User
> --- < Role
)
I wanted to fulfill this query:
createQuery() .from(qUser) .leftJoin(qUser.roles, qRole) .where(qUser.login.eq(login)) .singleResult( Projections.bean(User.class, qUser.id, qUser.login, qUser.password, GroupBy.set(Projections.bean(Role.class, qRole.id, qRole.code )).as(qUser.roles) ) );
The generated request looks like this, for me it is perfect:
SELECT user0_.ID AS col_0_0_, user0_.LOGIN AS col_1_0_, user0_.PASSWORD AS col_2_0_, role2_.ID AS col_4_0_, role2_.CODE AS col_5_0_ FROM public.USER user0_ LEFT OUTER JOIN public.USER_ROLE roles1_ ON user0_.ID=roles1_.USER_ID LEFT OUTER JOIN public.ROLE role2_ ON roles1_.ROLE_ID=role2_.ID WHERE user0_.LOGIN=? LIMIT ?
But I have java.lang.IllegalArgumentException: argument type mismatch
.
I was debugging, and I found out that the data from the database id is loading without problems. This is when QueryDsl / Hibernate did some introspection to create and initialize my objects that throw an exception.
The problem is that the User.setRoles(Set<Role>)
method called with the parameter long
: the identifier of the first list of Role
User
entities. Instead of creating Set
of Role
a, then map these roles to User
.
Is there a problem with the request? Or is it not supported by QueryDsl?
I am using QueryDsl 3.6.6 (I tested with 3.7.4: same result)