Skip to content

Spring Data API Extension query with field named like the class broken #48032

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
Michael-AT-Corporation opened this issue May 23, 2025 · 6 comments
Labels
area/spring Issues relating to the Spring integration kind/bug Something isn't working

Comments

@Michael-AT-Corporation
Copy link

Michael-AT-Corporation commented May 23, 2025

Describe the bug

Having a Repository with List<Parent> findByParent(String parent); causes the following exception at runtime when calling it:

org.hibernate.query.QueryArgumentException: Argument [test] of type [java.lang.String] did not match parameter type [at.atc.database.entities.Parent (n/a)]

This happens because the name of the field in the class is the same as the class. In this Example the field parent in the class Parent.
This happens since 3.18.0.CR1. Maybe because of this change: #44026

Expected behavior

No exception.

Actual behavior

Throws an exception when calling the method.

How to Reproduce?

QuarkusJpaTestFieldName.zip
Start the test getParent or mvn test.
This should cause the following exception:

org.hibernate.query.QueryArgumentException: Argument [test] of type [java.lang.String] did not match parameter type [at.atc.database.entities.Parent (n/a)]

Output of uname -a or ver

No response

Output of java -version

No response

Quarkus version or git rev

3.22.3

Build tool (ie. output of mvnw --version or gradlew --version)

No response

Additional information

No response

@Michael-AT-Corporation Michael-AT-Corporation added the kind/bug Something isn't working label May 23, 2025
@quarkus-bot quarkus-bot bot added the area/spring Issues relating to the Spring integration label May 23, 2025
Copy link

quarkus-bot bot commented May 23, 2025

/cc @aureamunoz (spring), @geoand (spring)

@yberbec
Copy link
Contributor

yberbec commented May 23, 2025

Hello @Michael-AT-Corporation, I've just resolved the issue. However, is there a real-world scenario where this would occur in a typical Quarkus project? It seems like you may have created a separate application to reproduce the problem. I'm ready to submit a PR if needed.

Image

Also, this link : https://github.com/quarkusio/quarkus/issues/44026 that you've shared in the description led me to an empty page, could you please check ?

Regards,
Yberbec

@Michael-AT-Corporation
Copy link
Author

Michael-AT-Corporation commented May 26, 2025

Hello @yberbec, thanks for looking into this issue.

Also, this link : https://github.com/quarkusio/quarkus/issues/44026 that you've shared in the description led me to an empty page, could you please check ?

I replaced the link. It should work now.

I don't think there are many scenarios where this problem occurs. In my project I have an Entity named Language which has an enum (also named Language) as field named language as well.

I would be happy if you could submit your pull request.

@yberbec
Copy link
Contributor

yberbec commented May 26, 2025

Hello @Michael-AT-Corporation, Should I submit your project QuarkusJpaTestFieldName as a zip file with the fix I did ? because what I asked for is to have this one scenario you have in Quarkus project, so I can create a PR.

Thanks

@Michael-AT-Corporation
Copy link
Author

@yberbec Yes please submit QuarkusJpaTestFieldName . Thanks

@yberbec
Copy link
Contributor

yberbec commented May 26, 2025

Here it is :
QuarkusJpaTestFieldName.zip
What I've changed is :
public interface ParentRepository extends JpaRepository<Parent, Long> { @Query("SELECT p FROM Parent p WHERE p.parent = :parentVal") List<Parent> findByParent(@Param("parentVal") String parent); }

By using the @Query annotation and explicitly naming the field, you avoid concerns about whether the class name matches the field name.
Thank you for sharing this issue :)
Yberbec

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/spring Issues relating to the Spring integration kind/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants