Thanks to visit codestin.com
Credit goes to github.com

Skip to content

fix(jpa): convert function-expression literal to the expression result type - #194

Merged
brunomendola merged 1 commit into
queritylib:mainfrom
vage88sg1:fix/function-value-conversion
Jul 11, 2026
Merged

brunomendola merged 1 commit into
queritylib:mainfrom
vage88sg1:fix/function-value-conversion

Conversation

@vage88sg1

Copy link
Copy Markdown
Contributor

Summary

Fixes #187: a SimpleCondition whose left side is a function expression passed the raw String literal to the predicate without conversion, so date/time comparisons failed at the database:

and(CURRENT_DATE = "2026-06-22")

Could not convert 'java.lang.String' to 'java.sql.Date' using 'org.hibernate.type.descriptor.java.JdbcDateJavaType' to wrap

Plain property paths were already converted via PropertyUtils.getActualPropertyValue; the function-expression branch used condition.getValue() as-is.

Changes

  • JpaOperatorMapper — converts the literal to the left expression's result type (Expression#getJavaType()); when JPA cannot infer it (COALESCE/NULLIF return null there), falls back to the type of the first property argument; keeps the raw value if no type can be resolved
  • DateValueExtractor — parses java.sql.Date/Time/Timestamp from their ISO-8601 forms (2026-06-22, 10:15:30, 2026-06-22T10:15:30); a plain java.util.Date target keeps the historical ISO-instant behavior
  • PropertyValueExtractorFactory — returns the no-op extractor for a null target type (defensive)
  • PropertyUtils — extracts getActualValue(Class, Object) as the reusable per-type conversion; getActualPropertyValue delegates to it

Testing

  • New integration tests in QuerityJpaImplTests (run on both H2 and PostgreSQL via Testcontainers):
    • CURRENT_DATE = "<today>" — literal converted to java.sql.Date, matches all rows
    • COALESCE(birthDate) = "<date>" — type resolved from the property argument
  • DateValueExtractorTests extended with the java.sql.* parse cases
  • ./mvnw verify — JaCoCo per-class coverage checks met

Fixes #187

🤖 Generated with Claude Code

…t type

A SimpleCondition whose left side is a function expression passed the raw
String literal to the predicate without conversion, so date/time comparisons
failed at the database (e.g. CURRENT_DATE = "2026-06-22" -> "Could not convert
java.lang.String to java.sql.Date"). Plain property paths were already
converted via PropertyUtils.

- JpaOperatorMapper converts the literal to leftExpression.getJavaType();
  when JPA cannot infer it (COALESCE/NULLIF), falls back to the first
  property argument's type
- DateValueExtractor now parses java.sql.Date/Time/Timestamp from their
  ISO-8601 forms (previously only java.util.Date via Instant.parse)
- PropertyValueExtractorFactory returns NoOp for a null target type
- PropertyUtils.getActualValue(Class, Object) extracts the reusable
  per-type conversion; getActualPropertyValue delegates to it
- Integration tests on H2/PostgreSQL for CURRENT_DATE and COALESCE(dateField)

Refs queritylib#187

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@brunomendola
brunomendola merged commit a0c6f43 into queritylib:main Jul 11, 2026
1 of 2 checks passed
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.

Function-expression conditions don't convert the literal value to the function's result type (date/time comparisons fail)

2 participants