Chris Popp (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%...
) *created* an issue
Hibernate ORM (
https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiNTcyOWFjOWRi...
) / Bug (
https://hibernate.atlassian.net/browse/HHH-17050?atlOrigin=eyJpIjoiNTcyOW...
) HHH-17050 (
https://hibernate.atlassian.net/browse/HHH-17050?atlOrigin=eyJpIjoiNTcyOW...
) JPA Criteria Queries using datediff and temporal units broken due to SqmDurationUnit
cast (
https://hibernate.atlassian.net/browse/HHH-17050?atlOrigin=eyJpIjoiNTcyOW...
)
Issue Type: Bug Affects Versions: 6.2.6 Assignee: Unassigned Created: 08/Aug/2023 13:28 PM
Priority: Minor Reporter: Chris Popp (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%...
)
I was trying to execute a JPA Criteria Query using Hibernate 6 calling the datediff
function, but it seems that due to the cast to SqmDurationUnit in
TimestampdiffFunction->TimestampdiffFunctionReturnTypeResolver I’m unable to supply a
temporal unit that will be accepted.
Given an entityManager the following demonstrates it when it throws an exception with the
failed cast:
CriteriaBuilder cb = entityManager.getCriteriaBuilder();
Expression<Long> dateDiffFunc = cb.function("DATEDIFF", Long.class,
criteriaBuilder.literal(TemporalUnit.MINUTE), criteriaBuilder.currentDate(),
criteriaBuilder.currentDate());
CriteriaQuery<Long> cr = cb.createQuery(Long.class)
.select(dateDiffFunc);
entityManager.createQuery(cr).getResultList();
Caused by: java.lang.ClassCastException: class
org.hibernate.query.sqm.tree.expression.SqmLiteral cannot be cast to class
org.hibernate.query.sqm.tree.expression.SqmDurationUnit
at
org.hibernate.dialect.function.TimestampdiffFunction$TimestampdiffFunctionReturnTypeResolver.resolveFunctionReturnType(TimestampdiffFunction.java:133)
(
https://hibernate.atlassian.net/browse/HHH-17050#add-comment?atlOrigin=ey...
) Add Comment (
https://hibernate.atlassian.net/browse/HHH-17050#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#100233- sha1:7fb7fe8 )