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

Query does not work with IN query and enums [DATAJDBC-619] #839

Closed
spring-projects-issues opened this issue Oct 20, 2020 · 5 comments
Closed
Assignees
Labels
in: repository status: declined type: bug

Comments

@spring-projects-issues
Copy link

@spring-projects-issues spring-projects-issues commented Oct 20, 2020

Johan Blomgren opened DATAJDBC-619 and commented

@Query("select id from entity where status IN (:status)")
fun find(status: List<Status>): List<String>

This does not work, it doesnt find any of my entities. My real query joins data from other tables and so on, so I want to use @Query

If u use NOT IN query i get error for the enum value

nested exception is org.h2.jdbc.JdbcSQLDataException: Hexadecimal string contains non-hex character: "OK"; SQL statement:

 


Affects: 2.0.4 (Neumann SR4)

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Oct 21, 2020

Jens Schauder commented

In the title you write about enums, but in the example, there are no enums involved. I'm therefore a little confused.

The best would be if you could create a reproducer and put it on github or attach it here

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Oct 21, 2020

Johan Blomgren commented

Jens Schauder Status in List<Status> was supposed to represent the enum

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Oct 21, 2020

Jens Schauder commented

Sorry, I read that as List<String> my mistake. I shouldn't try to work before the first coffee and without the correct glasses

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Oct 22, 2020

Jens Schauder commented

After taking a closer look I came to the conclusion that this is actually the correct behaviour.

Spring Data JDBC doesn't know what you want to do with that enum list and therefore doesn't know if it should be converted or not and if it should get converted, to what. 

With future version you'll be eventually be able to use SpEL expressions to do the conversion in the query. Keep an eye on DATAJDBC-397 for that.

Until then the workaround is to convert the enums to strings before passing them to the query method

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Oct 22, 2020

Johan Blomgren commented

Jens Schauder Ok, thanks! (y)

@spring-projects-issues spring-projects-issues added type: bug status: declined in: repository labels Dec 31, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: repository status: declined type: bug
Projects
None yet
Development

No branches or pull requests

2 participants