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(
at org.hibernate.engine.query.HQLQueryPlan.buildParameterMetadata(
at org.hibernate.engine.query.HQLQueryPlan.(
at org.hibernate.engine.query.HQLQueryPlan.(
at org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(
at org.hibernate.impl.SessionFactoryImpl.checkNamedQueries(
at org.hibernate.impl.SessionFactoryImpl.(
at org.hibernate.cfg.Configuration.buildSessionFactory(
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(

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:

name = "User.find",
query = "SELECT user FROM User user WHERE =: 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.

3 Gedanken zu „NullPointerException by NamedQuery using Hibernate JPA“

Kommentare sind geschlossen.