question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Exception "argument type mismatch" with projection bean and oneToMany association

See original GitHub issue

I 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:closed
  • Created 7 years ago
  • Comments:6

github_iconTop GitHub Comments

2reactions
thibaudsowacommented, Mar 28, 2019

@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…

User user = createQuery()
        .from(qUser)
        .where(qUser.login.eq(login))
        .singleResult(
                Projections.bean(User.class,
                        qUser.id,
                        qUser.login,
                        qUser.password
                )
        );


List<Role> roles = createQuery()
        .from(qUser)
        .innerJoin(qUser.roles, qRole)
        .where(qUser.id.eq(user.getId()))
        .list(
                Projections.bean(Role.class,
                        qRole.id,
                        qRole.code
                )
        );

user.setRoles(roles);
0reactions
stale[bot]commented, Jun 3, 2021

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

QueryDsl: Exception "argument type mismatch" with projection ...
QueryDsl: Exception "argument type mismatch" with projection bean and oneToMany or manyToMany association ... I wanted to perform this query:
Read more >
Hibernate ORM 6.1.6.Final User Guide - Red Hat on GitHub
Explicit association joins with join conditions; 16.8.4. join fetch for association ... Timestamp or any of the java.time types is considered an exception...
Read more >
Transformers.Aliastobean() Argument Type Mismatch - ADocLib
I'm working with a legacy database that stores booleans as the characters 'Y' and 'N'. What's the easiest way to map these values...
Read more >
Jdbi 3 Developer Guide
bindBean (new User(3, "David")) .execute(); // Easy mapping to any type return ... which could not be represented by the base Exception types...
Read more >
opencsv / Feature Requests / #85 Identify Column Name or ...
IllegalArgumentException : argument type mismatch at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found