Exception in thread “important” java.lang.NullPointerException
at org.hibernate.hql.ast.ParameterTranslationsImpl .getNamedParameterExpectedType(ParameterTranslationsImpl.java:63) at org.hibernate.engine.question.HQLQueryPlan.buildParameterMetadata(HQLQueryPlan.java:296) at org.hibernate.engine.question.HQLQueryPlan.(HQLQueryPlan.java:97) at org.hibernate.engine.question.HQLQueryPlan. (HQLQueryPlan.java:56) at org.hibernate.engine.question.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:72) at org.hibernate.impl.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:133) at org.hibernate.impl.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:112) at org.hibernate.impl.SessionImpl.createQuery(SessionImpl.java:1623
It might have been rather a lot higher if they’ve printed the title of variables which is null or something which factors to the fitting path, right here you solely have a clue that one thing occurred at ParameterTranslationsImpl.java at line 63.
Now by taking a look at code, you do get the impression that getNamedParameterInfo(title) is returning null and then you definitely go to test the supply code of getNamedParameterInfo() methodology, as an alternative of specializing in the HQL question
And, if you’re critical about bettering your Hibernate and JPA abilities then I additionally suggest you take a look at these greatest Hibernate and JPA programs on Udemy. It is an important useful resource to study Hibernate and JPA with Spring Boot in a hands-on and sensible method.
public Sort getNamedParameterExpectedType(String title) { return getNamedParameterInfo( title ).getExpectedType(); }
After spending a while I discovered that it was taking place because of an additional house given after the colon within the hibernate question (HQL). For instance, we had this as a Question String
choose EMP_ADDRESS from Worker the place EMP_ID = : ID
Do you discover the additional house? Effectively, it is not that straightforward to identify this sort of error. Now all it’s essential to do to take away this NullPointerException is that to take away that additional white house from HQL question String i.e.
choose EMP_ADDRESS from Worker the place EMP_ID = : ID
So all the time put consideration to what you place between colon and parameter in named SQL queries. After all, Hibernate can do a greater job to offer extra info whereas reporting errors as an alternative of simply throwing clean NullPointerException, which as an alternative of giving some clue can very nicely mislead you in numerous instructions.
Different Hibernate Articles and Interview Questions chances are you’ll like
- Distinction between First and Second stage cache in Hibernate? (reply)
- Distinction between get() and cargo() methodology in Hibernate? (reply)
- 5 Spring and Hibernate Coaching Programs for Java builders (record)
- 2 Books to Be taught Hibernate for Newcomers (books)
- 5 Books to Be taught Spring Framework for Newcomers (books)
- Why Hibernate Entity class shouldn’t be last in Java? (reply)
- 10 Hibernate Questions from Java Interviews (record)
- My favourite Hibernate and JPA Programs for Newcomers (programs)
Thanks for studying this text, should you like this text and the interview query then please share it with your folks and colleagues. In case you have any questions or suggestions then please drop a remark.