Skip to content

HHH-20302 Fix MAX/MIN on LocalDateTime and other java.time types when JAVA_TIME_USE_DIRECT_JDBC=true#12160

Open
MohammedAymanKhan wants to merge 2 commits intohibernate:mainfrom
MohammedAymanKhan:HHH-20302-fix-use-max-with-LocalDateTime
Open

HHH-20302 Fix MAX/MIN on LocalDateTime and other java.time types when JAVA_TIME_USE_DIRECT_JDBC=true#12160
MohammedAymanKhan wants to merge 2 commits intohibernate:mainfrom
MohammedAymanKhan:HHH-20302-fix-use-max-with-LocalDateTime

Conversation

@MohammedAymanKhan
Copy link
Copy Markdown
Contributor

@MohammedAymanKhan MohammedAymanKhan commented Apr 11, 2026

When hibernate.type.java_time_use_direct_jdbc=true, aggregate functions such as MAX() and MIN() on LocalDateTime (and other java.time temporal types) failed with:

FunctionArgumentException: Parameter 1 of function 'max()' has type 'COMPARABLE', but argument is of type 'java.time.LocalDateTime' mapped to '3009'

Root cause:
The ArgumentTypesValidator only checked jdbcType.isComparable(), which returns false for the new internal SQL type codes (e.g. SqlTypes.LOCAL_DATE_TIME = 3009) used by the direct JDBC binding.

Solution:
Updated isCompatible() in ArgumentTypesValidator to also accept types where jdbcType.isTemporal() == true.


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license
and can be relicensed under the terms of the LGPL v2.1 license in the future at the maintainers' discretion.
For more information on licensing, please check here.



Please make sure that the following tasks are completed:
Tasks specific to HHH-20302 (Bug):

  • Add test reproducing the bug
  • Add entries as relevant to migration-guide.adoc OR check there are no breaking changes

https://hibernate.atlassian.net/browse/HHH-20302

@hibernate-github-bot
Copy link
Copy Markdown

hibernate-github-bot bot commented Apr 12, 2026

Thanks for your pull request!

This pull request appears to follow the contribution rules.

› This message was automatically generated.

@MohammedAymanKhan MohammedAymanKhan marked this pull request as ready for review April 12, 2026 02:55
Copy link
Copy Markdown
Member

@mbellade mbellade left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @MohammedAymanKhan, please squash everything to a single commit once you're done addressing the review comments.

@MohammedAymanKhan MohammedAymanKhan force-pushed the HHH-20302-fix-use-max-with-LocalDateTime branch from c52f8a3 to 576a22c Compare April 13, 2026 16:54
Comment thread hibernate-core/src/main/java/org/hibernate/type/SqlTypes.java
Comment thread hibernate-core/src/main/java/org/hibernate/type/SqlTypes.java
Copy link
Copy Markdown
Member

@mbellade mbellade left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MohammedAymanKhan there are failing tests, not all DBs support native JDBC handling of all Java time types probably. You can restrict the test to one that we know is working with e.g. RequiresDialect(H2Dialect.class) on the test-class.

Also please squash everything to a 1/2 commits which respect the contribution rules (message starts with Jira key).

@sonarqubecloud
Copy link
Copy Markdown

@MohammedAymanKhan MohammedAymanKhan force-pushed the HHH-20302-fix-use-max-with-LocalDateTime branch from 2c530cb to 71a5f08 Compare April 16, 2026 02:04
@mbellade
Copy link
Copy Markdown
Member

mbellade commented Apr 16, 2026

@MohammedAymanKhan please avoid merge commits, you should rebase on top of main instead. Please squash everything to a single commit.

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.

3 participants