Skip to content

Enum value in where clause in Query annotation [DATAJDBC-409] #630

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

Closed
spring-projects-issues opened this issue Aug 27, 2019 · 2 comments
Closed
Assignees
Labels
type: bug A general bug

Comments

@spring-projects-issues
Copy link

Fábio Coutinho Valente opened DATAJDBC-409 and commented

I'm trying to create a query in my repository to find entities by a few properties and one of these properties is an enum.
Since Spring Data JDBC doesn't support derived queries yet, I'm creating a method with Query annotation in my entity repository.
In prodution we use PostgreSQL but ind development we use H2.
My method with query annotation is someting like:

@Query("SELECT t.* FROM ENTITY t WHERE t.date1= :date1 AND t.date2= :date2 AND t.entity_type = :entityType")
List<MyEntity> findByDate1AndDate2AndEntityType(@Param("date1") LocalDate date1, @Param("date2") LocalDate date2, @Param("entityType") EntityType entityType)

When I call this method I get an exception like

Caused by: org.h2.jdbc.JdbcSQLDataException: Hexadecimal string contains non-hex character: "FI"; SQL statement:

The FI is my enum value used in the search.
If I change my repository method to use String instead of EntityType enum and call it with the enum name it works fine and I receive a list of MyEntity with the property entityType with the right value.
Due to coherence I would like to keep using EntityType. Changing this method to use String would allow it to be called with any value that are not valid enum values which results in an empty list.

When derived queries support is released the idea is to remove this Query annotation


Issue Links:

@spring-projects-issues
Copy link
Author

Jens Schauder commented

This should be fixed by DATAJDBC-464

@ctailor2
Copy link
Contributor

This indeed appears to be fixed by DATAJDBC-464.

A new test on main to reproduce this issue already passes. The same test applied before the commits to resolve DATAJDBC-464 fails with the exception org.h2.jdbc.JdbcSQLDataException: Hexadecimal string with odd number of characters: "FIRST"; and passes when applied after these commits.

@schauder schauder added status: waiting-for-feedback We need additional information before we can continue and removed status: waiting-for-feedback We need additional information before we can continue labels Jan 26, 2022
@ctailor2 ctailor2 self-assigned this Apr 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug A general bug
Projects
None yet
Development

No branches or pull requests

3 participants