Exception "argument type mismatch" with projection bean and oneToMany association
See original GitHub issueI have an association manyToMany
between User
and Role
entities (User
>—< Role
)
I wanted to perform 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 query looks like this, for me it’s 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 a java.lang.IllegalArgumentException: argument type mismatch
.
I debugged and I found out that data from database id loaded without problem. This is when QueryDsl/Hibernate did some introspection to create and initialise my entities that the exception is throwed.
The problem is that the User.setRoles(Set<Role>)
method has called with a long
parameter: The ID of the first Role
entity list of the User
. Instead of create a Set
of Role
an then associate these roles to the User
.
Is there a problem with the query? Or is it not supported by QueryDsl?
I am using the QueryDsl 3.6.6 (I tested with 3.7.4: same result)
Issue Analytics
- State:
- Created 7 years ago
- Comments:6
@ilumer unfortunately we didn’t know how to solve this issue. So as an ugly workaround we do that with two requests: the first one without the sub-list and in the second one we request only the list. Finally we rebuild the object manually…
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.