NPE in CastFunction when casting a field named "date" to type "date" in HQL

Description

In Hibernate version "3.6.2.Final" when casting a field named "date" to type "date":

SELECT entity FROM DateEntity AS entity WHERE CAST(entity.date AS date) = ?

we encounter a NullPointerException in CastFunction:

java.lang.NullPointerException
at org.hibernate.dialect.function.CastFunction.render(CastFunction.java:56)
at org.hibernate.hql.ast.SqlGenerator.endFunctionTemplate(SqlGenerator.java:214)
at org.hibernate.hql.antlr.SqlGeneratorBase.methodCall(SqlGeneratorBase.java:2325)
...

If we rename the field "date" to "creationDate", the problem dissapears.
If we cast to "time" instead of "date", the problem dissapears.

We encountered this problem while using Hibernate version "3.6.0.Final" against MySQL 5.0.
Upgrading to Hibernate version "3.6.2.Final" did not resolve the problem.

We guess this problem is a bug in the Hibernate HQL parsing code. It might be a problem with our usage of Hibernate, in which case it would be helpful for Hibernate to return a useful error message.

Please find attached a minimal Maven test case (using HSQL memory DB) which demonstrates the problem.

The following JIRA issue maybe related to this problem:

- NPE in o.h.dialect.function.CastFunction

Credit to my colleague Sergey Shinkevich for creating the test case.

Thanks to the Hibernate team for a great product.

Attachments

3

Activity

Steve EbersoleOctober 28, 2015 at 5:50 PM

Sweet, thanks for verifying!

Jon MannOctober 28, 2015 at 5:47 PM

I have updated the attached test case to current version (5.0.2-Final).

It seems that the test case now passes!

Steve EbersoleOctober 28, 2015 at 3:25 AM

As part of verifying that this issue affects 5.0, please just set the "Affects version". Leave the "verify-affects-5.0" label and leave the issue in "Awaiting Response" status; these are critical for us to be able to track these verifications and triage them. Thanks.

Steve EbersoleOctober 27, 2015 at 7:16 PM

This bug report does not indicate that the reported issue affects version 5.x. Versions prior to 5.x are no longer maintained. It would be a great help to the Hibernate team and community for someone to verify that the reported issue still affects version 5.x. If so, please add the 5.x version that you verified with to the list of affected-versions and attach the (preferably SSCCE) test case you used to do the verification to the report; from there the issues will be looked at during our triage meetings.

For details, see http://in.relation.to/2015/10/27/great-jira-cleanup-2015/

Balint KrivanMay 11, 2015 at 1:44 PM

Hey!

I also would like to add something: CAST(... AS DATE) is not working only CAST(... AS date), shouldn't it be case-insensitive?

Out of Date

Details

Assignee

Reporter

Labels

Affects versions

Priority

Created March 18, 2011 at 1:38 PM
Updated October 28, 2015 at 5:51 PM
Resolved October 28, 2015 at 5:51 PM