NullPointerException by NamedQuery using Hibernate JPA
I just got a weird NullPointerException using Hibernate JPA. When creating my EntityManagerFactory, the usual logging started to appear and finished in stacktrace containing this:
Exception in thread "main" java.lang.NullPointerException
at org.hibernate.hql.ast.ParameterTranslationsImpl.getNamedParameterExpectedType(ParameterTranslationsImpl.java:63)
at org.hibernate.engine.query.HQLQueryPlan.buildParameterMetadata(HQLQueryPlan.java:296)
at org.hibernate.engine.query.HQLQueryPlan.(HQLQueryPlan.java:97)
at org.hibernate.engine.query.HQLQueryPlan.(HQLQueryPlan.java:56)
at org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:72)
at org.hibernate.impl.SessionFactoryImpl.checkNamedQueries(SessionFactoryImpl.java:400)
at org.hibernate.impl.SessionFactoryImpl.(SessionFactoryImpl.java:351)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1218)
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:691)
I could root it down to a NamedQuery in one of my Entites; when commenting it out, the creation went through fine. The Query definition looked like this:
@NamedQuery(
name = “User.find”,
query = “SELECT user FROM User user WHERE user.id =: id”
)
Did you spot the mistake? User dgynn on the Spring User Forum did: it’s the whitespace between the colon and the variable name. Really annoying, and took me more time to google than to write this post, so maybe this just helped you.






























Am 25. November 2006 um 00:15 Uhr
so i guess you did not report it in Hibernate jira where it would make a lot more sense…;)
Am 25. November 2006 um 11:43 Uhr
Now as you mention it… I wasn’t sure if this really is a bug in Hibernate, as I found a posting on the Hibernate forum about this for an older version, which didn’t get any answers. So I thought if it were a bug in Hibernate, someone would have responded or it would have been fixed by now.
I filed it as a minor bug:
http://opensource.atlassian.com/projects/hibernate/browse/ANN-496
Am 26. Mai 2009 um 15:11 Uhr
Pretty cool hehe! It is actually a bug though