-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Changes to null value type handling in versions 2.7.X breaks parameter types when using @Convert annotation #2710
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
Comments
Can you provide a minimal sample that reproduces the problem so we can better understand the context? |
Here is a simplified version of the database table we have.
The entity class could look like the following:
The converter looks like the following:
There is a @convert annotation used to convert boolean values to Char values ('Y' or 'N'). The idea here is to store booleans as chars but still manage the values in java code as booleans. The JPA repository call is defined in the following way:
The query has a conditional parameter. If you give it a boolean value, it queries rows where the "deleted" column is the desired value. If you give it null, then the WHERE clause is always true and it queries all rows no matter what the deleted value is. The converter worked perfectly with both null and non-null values before the 2.7.x update but now if you call the findPackages method with a null value, it breaks. The change that was made changed how null values are handled. It will now default to the type which the parameter was given in and the type for the converter is ignored. This will end up with us getting an error that boolean and char values cannot be compared with each other. |
We have the same Issue on our end. Will there be a fix, this is a blocker for us for the latest Spring Updates. An example was provided, what other feedback is needed? We also have an issue with "static" variables that need tobe converted.
|
Any news about this one? |
Hibernate contradicts itself with the entire conversion arrangement. We switched to Spring Data doesn't know about attribute converters and it isn't our business to dive into conversions that are handled by Hibernate. Providing type hints to |
There has been a fix in versions 2.7.0 and higher for parameter typing which is causing issues in JPA queries when using converters. #2370
This fix was made to help native queries handle null parameters but is also affecting JPA queries. In our situation we are using a converter to transform boolean values to chars eg. 'Y' or 'N'. When using these values, the data type binding is set as AttributeConverterTypeAdapter. This binding type is generated by @convert annotation in the entity class declaration and we want to keep it that way even in null cases. With the fix previously mentioned, in null cases this data type binding is overwritten by the parameter type.
The entity mapping with @convert annotation is the following:
And here is our JPA query:
The change in null value handling breaks our implementation and the JPA queries end up with the following error:
The binding works in the following way in hibernate:
If the value is an instance of TypedParameterValue, the parameter bind type is overwritten by the TypedParameterValue type. Previously null values were just bound without altering the binding type. Either this needs to be reverted for JPA queries or TypedParameterValue needs to fetch the parameter type from the ParameterMetadata where the data type generated by @convert annotation is stored.
The text was updated successfully, but these errors were encountered: