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

Querying Enum - Parameter value did not match expected type #61

Open
OrestisKariotis opened this issue Dec 12, 2022 · 1 comment
Open

Comments

@OrestisKariotis
Copy link

I am trying make a search based on one of my class's enum fields, but receive the following error:
InvalidDataAccessApiUsageException: Parameter value [FIRST] did not match expected type [*.MY_ENUM (n/a)];

To make it clear through an example, let's say I have an entity-class "MyClass" which has a field "MY_ENUM enumField", and MY_ENUM has the values ('FIRST', 'SECOND', 'THIRD').
I am trying to query for all MyClass entries that have the value 'FIRST' in their enumField.

My HTTP request is: localhost:8080/controller/search?search=enumField:FIRST.
I have also tried putting the FIRST query param in single & double quotes but the result was the same.

I have traced the problem to Spring's org.hibernate.query.spi.QueryParameterBindingValidator, method isValidBindValue().
Method isValidBindValue() checks whether value "FIRST" is of MY_ENUM type.

More specifically, the line that effectively causes the exception is expectedType.isInstance(value), where expectedType is "class MY_ENUM" and value is "FIRST", which evaluates to false and thus the error message - values checked via Intellij's debugger.

I have tried it with versions 0.2.3 & 0.2.4 of sipios/spring-search. My Spring Boot version is 2.7.3.
I saw that version 0.2.3 should support querying enums but I couldn't find any relative examples on how to do it, so it may be possible I have misunderstood how to use spring-search.

@ShishkinDmitriy
Copy link

Hi, it doesn't fork for me too.

Version 0.2.4. Starting by gradle bootRun
I found the same place in QueryParameterBindingValidator.. It checks that enum value is instanceof enum type.
They are the same types, BUT! loaded with different ClassLoader's:

  • RestartClassLoader
  • Launcher$AppClassLoader

That's why it thinks they are different types.

In #21 mentioned that start by jar -jar ... is some kind of workaround

Hope for quick fix

Best regards,
Dmitry

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants