Archie Cobbs (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%...
) *created* an issue
Hibernate ORM (
https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiODBlNTZlNzE3...
) / Bug (
https://hibernate.atlassian.net/browse/HHH-13908?atlOrigin=eyJpIjoiODBlNT...
) HHH-13908 (
https://hibernate.atlassian.net/browse/HHH-13908?atlOrigin=eyJpIjoiODBlNT...
) Hibernate makes incorrect assumption that TIME() function has type Date (should be
String) [TEST CASE] (
https://hibernate.atlassian.net/browse/HHH-13908?atlOrigin=eyJpIjoiODBlNT...
)
Issue Type: Bug Affects Versions: 5.4.12 Assignee: Unassigned Components:
hibernate-entitymanager Created: 25/Mar/2020 15:56 PM Labels: criteria Priority: Major
Reporter: Archie Cobbs (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%...
)
The MySQL TIME() function returns a String, as is documented here (
https://dev.mysql.com/doc/refman/8.0/en/date-and-time-functions.html#func... ) :
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:
cq.select(foo)
.where(cb.lessThanOrEqualTo(
cb.function("TIME", String.class, foo.get(Foo_.startTime)),
"17:00:00"));
However, when executing that query Hibernate throws this exception:
java.lang.IllegalArgumentException: Parameter value [17:00:00] did not match expected type
[java.util.Date (n/a)]
at
org.hibernate.query.spi.QueryParameterBindingValidator.validate(QueryParameterBindingValidator.java:54)
at
org.hibernate.query.spi.QueryParameterBindingValidator.validate(QueryParameterBindingValidator.java:27)
at
org.hibernate.query.internal.QueryParameterBindingImpl.validate(QueryParameterBindingImpl.java:90)
at
org.hibernate.query.internal.QueryParameterBindingImpl.setBindValue(QueryParameterBindingImpl.java:55)
at
org.hibernate.query.internal.AbstractProducedQuery.setParameter(AbstractProducedQuery.java:489)
at
org.hibernate.query.internal.AbstractProducedQuery.setParameter(AbstractProducedQuery.java:110)
at
org.hibernate.query.criteria.internal.compile.CriteriaCompiler$1$1.bind(CriteriaCompiler.java:135)
at
org.hibernate.query.criteria.internal.CriteriaQueryImpl$1.buildCompiledQuery(CriteriaQueryImpl.java:360)
at
org.hibernate.query.criteria.internal.compile.CriteriaCompiler.compile(CriteriaCompiler.java:165)
at
org.hibernate.internal.AbstractSharedSessionContract.createQuery(AbstractSharedSessionContract.java:742)
at org.hibernate.internal.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:23)
at org.hibernate.bugs.JPAUnitTestCase.hhh123Test(JPAUnitTestCase.java:48)
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-fu...
(
https://hibernate.atlassian.net/browse/HHH-13908#add-comment?atlOrigin=ey...
) Add Comment (
https://hibernate.atlassian.net/browse/HHH-13908#add-comment?atlOrigin=ey...
)
Get Jira notifications on your phone! Download the Jira Cloud app for Android (
https://play.google.com/store/apps/details?id=com.atlassian.android.jira....
) or iOS (
https://itunes.apple.com/app/apple-store/id1006972087?pt=696495&ct=Em...
) This message was sent by Atlassian Jira (v1001.0.0-SNAPSHOT#100122- sha1:092c6a7 )