-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Annotated query with wildcard-appended named parameter does not handle null in 2.7.0 #2548
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
Possibly related to #2544 ? |
Possibly related to #2461. |
Related: #2549 |
Having the same problem with spring-data-jpa to 2.7.0 |
Is there any plan for this issue ? (and the other related issues) |
Properly handle null values with like or contains. Null values are wrapped with a special handler when interacting with Hibernate. However, this becomes an issue for queries when LIKE or CONTAINS are applied. In this situation, the null needs to be condensed into an empty string and any wildcards can then be applied with expected results. Closes #2548, #2570. Supercedes: #2585. Related: #2461, #2544#
Null values are wrapped with a special handler when interacting with Hibernate. However, this becomes an issue for queries when LIKE or CONTAINS are applied. In this situation, the null needs to be condensed into an empty string and any wildcards can then be applied with expected results. Closes #2548, #2570. Supercedes: #2585. Related: #2461, #2544#
Null values are wrapped with a special handler when interacting with Hibernate. However, this becomes an issue for queries when LIKE or CONTAINS are applied. In this situation, the null needs to be condensed into an empty string and any wildcards can then be applied with expected results. Closes #2548, #2570. Supercedes: #2585. Related: #2461, #2544#
@gregturn seems like the change you made at 3d8b287 addresses the original problem in 3.0.0-M5 release line. However, it is not obvious to me if this issue has to be handled in a different way in 2.7.x or will be backported to 2.7.x automatically during the next release. I am maintaining an application that is stuck in 2.6.x due to this issue which is closed now, I tried to reproduce with spring-boot 2.7.3 and the issue still persists there. Any feedback regarding 2.7.x would be really helpful for the app maintainers who still use 2.6.x as noted by quaff here |
Null values are wrapped with a special handler when interacting with Hibernate. However, this becomes an issue for queries when LIKE or CONTAINS are applied. In this situation, the null needs to be condensed into an empty string and any wildcards can then be applied with expected results. Closes #2548, #2570. Supercedes: #2585. Related: #2461, #2544#
This was backported to |
…g for string params. Fixes spring-projects#2653 Related tickets spring-projects#2548
@jonhakr @gregturn the original issue was fixed however there still is a problem with null values. ExampleThe null value previously was bound as null instead of wildcard like it is now. Using the query from the demo app:
We change the data so it contains a null value in one of the records like so:
And when we run a query with parameters set to null the following parameters are bound:
This in turn returns only 2 of the records when all records should be returned:
However on version 2.6.4 before this issue appeared the null parameter is picked up by the is null condition and isn't turned into a wildcard:
Which correctly returns all records. |
We have the same issue with 2.7.4 and as workaround it helps to use (we use postgres, but other db I think it's possible to use the appropriate concatenation func) |
I have updated the example with null data in DB, and can confirm that this still fails for 2.7.5 (also fails for 2.7.0 as before), as stated by @michalkleszcz12, since the injected parameter in the |
@jonhakr Check out the snapshots to see if things are now working as expected. |
Hi 👋 For Information, I bump to Spring Boot 2.7.5 yesterday. Some tests failed after the bump. Regards |
Can confirm what @dwursteisen is saying. Updated example with spring-data set to that snapshot, and all tests went green |
Duplicate of #2653. |
Strictly speaking, #2653 is a duplicate of this |
I am still facing this issue with Spring Boot 3+ for the edge case of enum object nested within another object. Here's an example:
This worked with 2.7.x |
2.7.x Be careful if you use the Spring Native project. You should create a hint for the @TypeHint(types = org.hibernate.jpa.TypedParameterValue.class)
public class YourNativeHibernateHints implements NativeConfiguration {
} The hint for this type is missing from the native configuration for Hibernate. Without this hint, your binary will use select distinct stationent0_.id as col_0_0_
from stations stationent0_
where
(NULL is null or stationent0_.city_id=NULL) and
('%org.hibernate.jpa.TypedParameterValue@701ac132%' is null or
lower(stationent0_.address) like '%org.hibernate.jpa.TypedParameterValue@701ac132%'
) |
Spring Boot 3.1.4 : Same problem persists (in my case for a Boolean parameter), but, resolvable as follows :
This throws : Caused by: org.postgresql.util.PSQLException: ERROR: operator does not exist: character varying = boolean The problem is with the Boolean multiple parameter. AND NOTE: Testing always worked fine without any problem, so I'd say this was resolved somewhow in Spring Test, but It would be nice though to have it working without the need of SPeL as in the versions prior to 2.7.x. |
Same error in 3.1.5 |
Context
We often create queries with optional filtering on parameters (ignore them when null) like so:
As noted in Example 62 in https://docs.spring.io/spring-data/jpa/docs/current/reference/html/#jpa.query-methods.at-query.advanced-like
This worked fine previously, but after upgrading til 2.7.0 it does not seem to work when such a named parameter is null, which it is intended to be when using that to implement optional filtering like this.
Problem
When the named parameter is null, the binded value is the literal string
org.hibernate.jpa.TypedParameterValue@<number>
augmented with the wildcard parameter, instead of just null.I have prepared a demo app that showcases the issue: https://github.com/jonhakr/spring-data-jpa-null-optional-query
The query above is generated as such:
When
name
is null it works fine, and the resulting bound parameter values are:However, if the wildcard appended
desc
is null, the resulting bound parameter values are:Simply setting spring-data-jpa to 2.6.4 makes this work fine again
The text was updated successfully, but these errors were encountered: