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 boot works incorrectly with nativeQuery with enum param with H2 and mariadb #3251

Closed
sergeybaltak opened this issue Feb 24, 2025 · 3 comments
Labels
for: external-project For an external project and not something we can fix

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 24, 2025
@mp911de
Copy link
Member

mp911de commented Feb 25, 2025

@Enumerated(EnumType.STRING) are JPA types and so there is nothing we can do here.

Have you tried running entityManager.createNativeQuery("SELECT * FROM order_ s WHERE s.status = :status", Order.class).setParameter("status", OrderStatus.FEEDBACK).getResultList() to inspect results?

@mp911de mp911de added the status: waiting-for-feedback We need additional information before we can continue label Feb 25, 2025
@sergeybaltak
Copy link
Author

The result is Order(id=2, status=ACTIVE).

@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 25, 2025
@mp911de
Copy link
Member

mp911de commented Feb 26, 2025

That indicates that Hibernate is having issues with the enum translation. Please file a ticket with the Hibernate issue tracker and verify that your query arrangement is supported.

@mp911de mp911de closed this as not planned Won't fix, can't repro, duplicate, stale Feb 26, 2025
@mp911de mp911de added for: external-project For an external project and not something we can fix and removed status: waiting-for-triage An issue we've not yet triaged status: feedback-provided Feedback has been provided labels Feb 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
for: external-project For an external project and not something we can fix
Projects
None yet
Development

No branches or pull requests

3 participants