Chris Popp (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%...
) *updated* an issue
Hibernate ORM (
https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiZmI3M2NjYzk0...
) / Bug (
https://hibernate.atlassian.net/browse/HHH-17050?atlOrigin=eyJpIjoiZmI3M2...
) HHH-17050 (
https://hibernate.atlassian.net/browse/HHH-17050?atlOrigin=eyJpIjoiZmI3M2...
) JPA Criteria Queries using datediff and temporal units broken due to SqmDurationUnit
cast (
https://hibernate.atlassian.net/browse/HHH-17050?atlOrigin=eyJpIjoiZmI3M2...
)
Change By: 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:
{noformat}CriteriaBuilder cb = entityManager.getCriteriaBuilder();
Expression<Long> dateDiffFunc = cb.function("DATEDIFF", Long.class,
criteriaBuilder cb.literal(TemporalUnit.MINUTE), criteriaBuilder cb.currentDate(),
criteriaBuilder cb.currentDate());
CriteriaQuery<Long> cr = cb.createQuery(Long.class)
.select(dateDiffFunc);
entityManager.createQuery(cr).getResultList();{noformat}
{quote}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){quote}
(
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#100234- sha1:9e2db29 )