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

Enum type in Query annotation does not work in in clause #1212

Closed
holmofy opened this issue Apr 2, 2022 · 2 comments
Closed

Enum type in Query annotation does not work in in clause #1212

holmofy opened this issue Apr 2, 2022 · 2 comments
Assignees
Labels
type: bug A general bug

Comments

@holmofy
Copy link

holmofy commented Apr 2, 2022

@Query("select category, text, count(id) as count" +
        " from table_name" +
        " where from_type in (:fromTypes)" +
        " group by text, category")
List<Stats> statsByFromType(Collection<FromType> fromTypes);

The FromType here is an enum type, but the in clause in the Query annotation cannot find the data.

The executed sql shows that FromType is converted to int type, but the actual string type is stored in the database

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Apr 2, 2022
@mp911de mp911de added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged labels Apr 4, 2022
@mp911de
Copy link
Member

mp911de commented Apr 4, 2022

Seems related to #630

@holmofy
Copy link
Author

holmofy commented Apr 4, 2022

I also found that issue, but the problem is different. This problem occurs in the in clause. the parameter is a Collection.

I now use a compromise, which adds a default method. This default method calls the method of the Collection<String> parameter internally.

@Query("select category, text, count(id) as count" +
        " from table_name" +
        " where from_type in (:fromTypes)" +
        " group by text, category")
List< Stats > statsByFromTypeString(Collection<String> fromTypes);

default List<Stats> statsByFromType(Collection<PaperFromType> fromTypes) {
    return statsByCategoriesString(fromTypes.stream().map(PaperFromType::name).collect(Collectors.toList()));
}

But it's rather awkward to use. Can this collection parameter problem be solved?

schauder pushed a commit that referenced this issue May 17, 2022
+ Copy logic from QueryMapper#convertToJdbcValue to resolve Iterable
  arguments on findBy* query methods to resolve the same for @query.
+ Use parameter ResolvableType instead of Class to retain generics info.

Original pull request #1226
Closes #1212
schauder added a commit that referenced this issue May 17, 2022
Original pull request #1226
See #1212
schauder added a commit that referenced this issue May 17, 2022
Original pull request #1226
See #1212
schauder pushed a commit that referenced this issue May 17, 2022
+ Copy logic from QueryMapper#convertToJdbcValue to resolve Iterable
  arguments on findBy* query methods to resolve the same for @query.
+ Use parameter ResolvableType instead of Class to retain generics info.

Original pull request #1226
Closes #1212
schauder added a commit that referenced this issue May 17, 2022
Original pull request #1226
See #1212
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
4 participants