Skip to content

Fix LIKE on non-String fields failing on PostgreSQL#3008

Open
clayly wants to merge 2 commits intoeclipse-hawkbit:masterfrom
clayly:fix/like-on-non-string-fields
Open

Fix LIKE on non-String fields failing on PostgreSQL#3008
clayly wants to merge 2 commits intoeclipse-hawkbit:masterfrom
clayly:fix/like-on-non-string-fields

Conversation

@clayly
Copy link
Copy Markdown

@clayly clayly commented Apr 9, 2026

Summary

The like() and notLike() methods in SpecificationBuilder handle RSQL wildcard queries like id==* by translating them to SQL LIKE '%'. When applied to non-String columns (e.g. bigint), this fails on PostgreSQL and compatible databases with:

ERROR: operator does not exist: bigint ~~ text

The existing code had a fallback that caught Hibernate's CoercionException to convert this to IS NOT NULL, but:

  1. The project uses EclipseLink, not Hibernate — so the exception was never thrown
  2. EclipseLink sends the invalid SQL directly to the database, which rejects it
  3. This means the test DeploymentManagementTest.verifyActionVisibility has never passed on PostgreSQL — only on H2

The 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 as IS NOT NULL.

Changes

  • SpecificationBuilder.like(): early return isNotNull() when sqlValue is % and field is non-String
  • SpecificationBuilder.notLike(): early return isNull() for the same case
  • Removed the now-unnecessary try/catch and unused PersistenceException import

Test plan

  • DeploymentManagementTest.verifyActionVisibility passes on H2 (default)
  • DeploymentManagementTest.verifyActionVisibility passes on PostgreSQL 15
  • DeploymentManagementTest.verifyActionVisibility passes on YugabyteDB (PostgreSQL 15.12-YB-2025.2.2.2-b0)

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.
@hawkbit-bot
Copy link
Copy Markdown

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.
Please make sure you read the contribution guide and signed the Eclipse Contributor Agreement (ECA).

@clayly
Copy link
Copy Markdown
Author

clayly commented Apr 9, 2026

Hi everyone! It follows the goal of #3007, but fixes issue of slightly other kind.

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

Successfully merging this pull request may close these issues.

2 participants