[hibernate-issues] [JIRA] (HHH-13908) Hibernate makes incorrect assumption that TIME() function has type Date (should be String) [TEST CASE]

Archie Cobbs (JIRA) jira at hibernate.atlassian.net
Wed Mar 25 18:56:42 EDT 2020


Archie Cobbs ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%3A73577a99-7056-4b5c-950c-65e8428c6ff3 ) *created* an issue

Hibernate ORM ( https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiODBlNTZlNzE3NTAwNDdlNjhlMzRjNjE3MmZhYmEyNGMiLCJwIjoiaiJ9 ) / Bug ( https://hibernate.atlassian.net/browse/HHH-13908?atlOrigin=eyJpIjoiODBlNTZlNzE3NTAwNDdlNjhlMzRjNjE3MmZhYmEyNGMiLCJwIjoiaiJ9 ) HHH-13908 ( https://hibernate.atlassian.net/browse/HHH-13908?atlOrigin=eyJpIjoiODBlNTZlNzE3NTAwNDdlNjhlMzRjNjE3MmZhYmEyNGMiLCJwIjoiaiJ9 ) Hibernate makes incorrect assumption that TIME() function has type Date (should be String) [TEST CASE] ( https://hibernate.atlassian.net/browse/HHH-13908?atlOrigin=eyJpIjoiODBlNTZlNzE3NTAwNDdlNjhlMzRjNjE3MmZhYmEyNGMiLCJwIjoiaiJ9 )

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%3A73577a99-7056-4b5c-950c-65e8428c6ff3 )

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#function_time ) :

> 
> 
> 
> 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-function-bug

( https://hibernate.atlassian.net/browse/HHH-13908#add-comment?atlOrigin=eyJpIjoiODBlNTZlNzE3NTAwNDdlNjhlMzRjNjE3MmZhYmEyNGMiLCJwIjoiaiJ9 ) Add Comment ( https://hibernate.atlassian.net/browse/HHH-13908#add-comment?atlOrigin=eyJpIjoiODBlNTZlNzE3NTAwNDdlNjhlMzRjNjE3MmZhYmEyNGMiLCJwIjoiaiJ9 )

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.core&referrer=utm_source%3DNotificationLink%26utm_medium%3DEmail ) or iOS ( https://itunes.apple.com/app/apple-store/id1006972087?pt=696495&ct=EmailNotificationLink&mt=8 ) This message was sent by Atlassian Jira (v1001.0.0-SNAPSHOT#100122- sha1:092c6a7 )
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/hibernate-issues/attachments/20200325/afff3c04/attachment.html 


More information about the hibernate-issues mailing list