Fix LIKE on non-String fields failing on PostgreSQL#3008
Open
clayly wants to merge 2 commits intoeclipse-hawkbit:masterfrom
Open
Fix LIKE on non-String fields failing on PostgreSQL#3008clayly wants to merge 2 commits intoeclipse-hawkbit:masterfrom
clayly wants to merge 2 commits intoeclipse-hawkbit:masterfrom
Conversation
The like() and notLike() methods in SpecificationBuilder relied on catching a Hibernate-specific CoercionException when LIKE was applied to non-String fields (e.g. bigint) with a wildcard-only value. However, with EclipseLink the invalid SQL is sent directly to the database, where PostgreSQL and compatible databases (YugabyteDB, CockroachDB) reject it with "operator does not exist: bigint ~~ text". Move the non-String field check before building the SQL predicate, making it database-agnostic and JPA-provider-agnostic. A wildcard-only LIKE on a non-String field is semantically equivalent to IS NOT NULL (and NOT LIKE to IS NULL), which is what the fallback already produced.
|
Thanks @clayly for taking the time to contribute to hawkBit! We really appreciate this. Make yourself comfortable while I'm looking for a committer to help you with your contribution. |
Author
|
Hi everyone! It follows the goal of #3007, but fixes issue of slightly other kind. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The
like()andnotLike()methods inSpecificationBuilderhandle RSQL wildcard queries likeid==*by translating them to SQLLIKE '%'. When applied to non-String columns (e.g.bigint), this fails on PostgreSQL and compatible databases with:The existing code had a fallback that caught Hibernate's
CoercionExceptionto convert this toIS NOT NULL, but:DeploymentManagementTest.verifyActionVisibilityhas never passed on PostgreSQL — only on H2The fix moves the non-String field check before building the SQL predicate, making it both database-agnostic and JPA-provider-agnostic. The semantic equivalence is preserved:
LIKE '%'on a non-null column matches all rows, same asIS NOT NULL.Changes
SpecificationBuilder.like(): early returnisNotNull()whensqlValueis%and field is non-StringSpecificationBuilder.notLike(): early returnisNull()for the same casePersistenceExceptionimportTest plan
DeploymentManagementTest.verifyActionVisibilitypasses on H2 (default)DeploymentManagementTest.verifyActionVisibilitypasses on PostgreSQL 15DeploymentManagementTest.verifyActionVisibilitypasses on YugabyteDB (PostgreSQL 15.12-YB-2025.2.2.2-b0)