Skip to content
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

Spring data jpa works incorrectly with nativeQuery with enum param with H2 and mariadb #3790

Closed
sergeybaltak opened this issue Feb 26, 2025 · 4 comments
Labels
status: invalid An issue that we don't feel is valid

Comments

@sergeybaltak
Copy link

I have an entity with enum field. When I use native query with param of enum type and @Enumerated(EnumType.STRING) annotation it works incorrectly. I use spring-boot-starter-parent 3.4.2. I try to write the native sql query with parameter of enum type. And repository doesn't recognise it correctly. It works fine when I use spring data like findByStatus but it doesn't work for native queries. It gets entites with incorrect status. If you reorder enum values you will get another results. When I don't use @Enumerated(EnumType.STRING) annotation it works correctly.

https://stackoverflow.com/questions/79449411/spring-boot-works-incorrectly-with-nativequery-with-enum-param-with-h2-and-maria

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Feb 26, 2025
@christophstrobl
Copy link
Member

If you'd like us to spend some time investigating, please take the time to provide a complete minimal sample (something that we can unzip or git clone, build, and deploy) that reproduces the problem.

@christophstrobl christophstrobl added status: waiting-for-feedback We need additional information before we can continue and removed status: waiting-for-triage An issue we've not yet triaged labels Feb 27, 2025
@sergeybaltak
Copy link
Author

OrderRepositoryTest

demo.zip

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Feb 27, 2025
@christophstrobl
Copy link
Member

Thank you for the sample. Spring Data does not do anything different from when using a plain EntityManager.
If you change the OrderStatus in your tests below from FEEDBACK to ACTIVE you'll get exactly the same behaviour.

entityManager.createNativeQuery("SELECT * FROM order_ s WHERE s.status = :status", Order.class)
    .setParameter("status", OrderStatus.FEEDBACK)

@christophstrobl christophstrobl closed this as not planned Won't fix, can't repro, duplicate, stale Feb 28, 2025
@christophstrobl christophstrobl added status: invalid An issue that we don't feel is valid and removed status: feedback-provided Feedback has been provided labels Feb 28, 2025
@sergeybaltak
Copy link
Author

Ok. But do you see any errors in spring code or not? Or it works fine and it is not spring project error? If it is related to spring project what exactly spring project team could help to solve this error?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: invalid An issue that we don't feel is valid
Projects
None yet
Development

No branches or pull requests

3 participants