Réda Housni Alaoui (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%...
) *created* an issue
Hibernate ORM (
https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiMDRiYTYyYjc2...
) / Bug (
https://hibernate.atlassian.net/browse/HHH-16130?atlOrigin=eyJpIjoiMDRiYT...
) HHH-16130 (
https://hibernate.atlassian.net/browse/HHH-16130?atlOrigin=eyJpIjoiMDRiYT...
) Unable to invoke Postgres date_trunc function via CriteriaApi (
https://hibernate.atlassian.net/browse/HHH-16130?atlOrigin=eyJpIjoiMDRiYT...
)
Issue Type: Bug Affects Versions: 6.1.6 Assignee: Unassigned Created: 02/Feb/2023 01:30 AM
Priority: Major Reporter: Réda Housni Alaoui (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%...
)
The following snippet was working on version 5.6.14 on Postgres 14:
CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
CriteriaQuery<Date> query = criteriaBuilder.createQuery(Date.class);
query.select(criteriaBuilder.function( "date_trunc" , Date.class,
criteriaBuilder.literal( "year" ), criteriaBuilder.currentTimestamp()));
entityManager.createQuery(query).getSingleResult();
On 6.1.6, it fails with
arameter 1 of function date_trunc() has type TEMPORAL_UNIT, but argument is of type
java.lang. Object
org.hibernate.QueryException: Parameter 1 of function date_trunc() has type TEMPORAL_UNIT,
but argument is of type java.lang. Object
at app
//org.hibernate.query.sqm.produce.function.ArgumentTypesValidator.throwError(ArgumentTypesValidator.java:251)
at app
//org.hibernate.query.sqm.produce.function.ArgumentTypesValidator.validate(ArgumentTypesValidator.java:111)
at app
//org.hibernate.query.sqm.function.AbstractSqmFunctionDescriptor.generateSqmExpression(AbstractSqmFunctionDescriptor.java:104)
at app
//org.hibernate.query.sqm.internal.SqmCriteriaNodeBuilder.function(SqmCriteriaNodeBuilder.java:1643)
at app
//org.hibernate.query.sqm.internal.SqmCriteriaNodeBuilder.function(SqmCriteriaNodeBuilder.java:176)
at app
//org.hibernate.orm.test.query.hql.FunctionTests.lambda$testDateTruncFunctionViaCriteriaApi$22(FunctionTests.java:542)
at app
//org.hibernate.testing.orm.transaction.TransactionUtil.wrapInTransaction(TransactionUtil.java:49)
at app
//org.hibernate.testing.orm.transaction.TransactionUtil.inTransaction(TransactionUtil.java:24)
at app
//org.hibernate.testing.orm.junit.SessionFactoryExtension$SessionFactoryScopeImpl.inTransaction(SessionFactoryExtension.java:375)
at app
//org.hibernate.testing.orm.junit.SessionFactoryExtension$SessionFactoryScopeImpl.inTransaction(SessionFactoryExtension.java:352)
at app
//org.hibernate.orm.test.query.hql.FunctionTests.testDateTruncFunctionViaCriteriaApi(FunctionTests.java:536)
But
https://github.com/Cosium/hibernate-orm/blob/94b20bafc84d3f26fa37bf41ed79...
(
https://github.com/Cosium/hibernate-orm/blob/94b20bafc84d3f26fa37bf41ed79...
) proves it works via HQL .
(
https://hibernate.atlassian.net/browse/HHH-16130#add-comment?atlOrigin=ey...
) Add Comment (
https://hibernate.atlassian.net/browse/HHH-16130#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#100214- sha1:06410ea )