Hibernate makes incorrect assumption that TIME() function has type Date (should be String) [TEST CASE]

Description

The MySQL TIME() function returns a String, as is documented here:

Extracts the time part of the time or datetime expression expr and returns it as a string.

Therefore, one would expect this CriteriaQuery logic, which is doing a comparison between two String values, to work:

However, when executing that query Hibernate throws this exception:

Note that I've explicitly specified String.class as the function's return type. And in fact, if you replace the function name "TIME" with something else (e.g., "FOOBAR") the query compiles just fine. So Hibernate must have some built-in assumption that the TIME() function on every database returns a value of type Date, not String.

But obviously that's incorrect in the case of MySQL.

So it seems like one of the following fixes is needed here:

  • Disable any built-in implicit assumptions about the TIME() function having type Date - i.e., always trust what the caller says is the function's return type in CriteriaBuilder.function().

  • Move the TIME() function's return type assumption into the dialect

I have a test case here:

https://github.com/archiecobbs/hibernate-test-case-templates/tree/time-function-bug

Environment

None

Activity

Show:
Nathan Xu
August 28, 2020, 6:06 PM
Edited

PR created at: . The easiest ticket of yours so far, :).

Assignee

Nathan Xu

Reporter

Archie Cobbs

Fix versions

Labels

backPortable

Backport?

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Affects versions

Priority

Major
Configure