[hibernate-issues] [Hibernate-JIRA] Commented: (HHH-6024) NPE in CastFunction when casting a field named "date" to type "date" in HQL

Robin Sander (JIRA) noreply at atlassian.com
Fri Jul 1 07:40:54 EDT 2011


    [ http://opensource.atlassian.com/projects/hibernate/browse/HHH-6024?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=42744#action_42744 ] 

Robin Sander commented on HHH-6024:
-----------------------------------

With Hibernate 3.6.5 and PostgreSQL 8.4 I get the same NPE ({{org.hibernate.dialect.function.CastFunction.render(CastFunction.java:56)}}) when using a simple cast like:
{noformat}CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Tuple> criteria = cb.createTupleQuery();
Root<VoteArtist> vote = criteria.from(VoteArtist.class);

Expression<Double> avgRatingExpression = cb.avg(vote.get(Rating_.rating).as(Double.TYPE)); // XXX as(Double.TYPE) cause NPE in CastFunction
criteria.multiselect(cb.count(vote), avgRatingExpression);
criteria.orderBy(cb.desc(avgRatingExpression));
List<Tuple> result = em.createQuery(criteria).getResultList();
{noformat} 

The strange thing is that CastFunction tries to find a heuristic type for "float8" which is the SQL type PostgreSQLDialect registers for type double.

> NPE in CastFunction when casting a field named "date" to type "date" in HQL
> ---------------------------------------------------------------------------
>
>                 Key: HHH-6024
>                 URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-6024
>             Project: Hibernate Core
>          Issue Type: Bug
>    Affects Versions: 3.6.2
>         Environment: Hibernate 3.6.0.Final and 3.6.2.Final
> MySQL 5.0
>            Reporter: Jon Mann
>         Attachments: hibernate-cast-date.zip
>
>
> 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:
>   HHH-3770 - 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.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        


More information about the hibernate-issues mailing list