Hibernate Nullpointerexception Due To Infinite Inward Hql Named Queries

If y'all are using Hibernate for implementing persistence layer inward Java as well as JEE application from pair of years as well as thus y'all would possess got seen this notorious NullPointerException while executing HQL named queries, Exception inward thread “main” java.lang.NullPointerException at org.hibernate.hql.ast.ParameterTranslationsImpl .getNamedParameterExpectedType (ParameterTranslationsImpl.java:63).  Hibernate has around pitiful logging inward instance of Exception, which has caused me hours to debug a uncomplicated problem. By looking at NullPointerException below (look sum stacktrace below), I had no clue that it's coming because of a missing infinite on HQL (Hibernate Query language) query. You tin every bit good accept a await if y'all tin figure this out :


Exception inward 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.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:133) at org.hibernate.impl.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:112) at org.hibernate.impl.SessionImpl.createQuery(SessionImpl.java:1623

 If y'all are using Hibernate for implementing persistence layer inward Java as well as JEE application Hibernate NullPointerException due to Space inward HQL named queriesHQL query


public Type getNamedParameterExpectedType(String name) {     return getNamedParameterInfo( lift ).getExpectedType(); }

After spending around fourth dimension I institute that it was happening due to an extra infinite given afterwards the colon inward the hibernate query (HQL). For illustration nosotros had this every bit query String

select EMP_ADDRESS from Employee where EMP_ID = :  ID

Do y'all divulge the extra space? Well it's non that slow to location this sort of error. Now all y'all demand to create to withdraw this NullPointerException is that to withdraw that extra white infinite from HQL query String i.e.

select EMP_ADDRESS from Employee where EMP_ID = : ID

So e'er position attending what y'all position betwixt colon as well as parameter inward named SQL queries. Of class Hibernate tin create amend project to render to a greater extent than information spell reporting fault instead of only throwing blank NullPointerException, which instead of giving around clue tin really good mislead y'all into dissimilar direction. This is the employment amongst whatever language, they tin non validate anything which is within String, wouldn't it endure amend if your HQL are every bit good larn validated at compile fourth dimension instead of runtime?

Further Learning
answer)
  • Difference betwixt get() as well as load() method inward Hibernate? (answer)
  • 5 Spring as well as Hibernate Training Courses for Java developers (list)
  • 2 Books to Learn Hibernate inward 2017 (books)
  • 5 Books to Learn Spring Framework inward 2017 (books)
  • Why Hibernate Entity class should non endure terminal inward Java? (answer)
  • 10 Hibernate Questions from Java Interviews (list)

  • Thanks for reading this article, if y'all similar this article as well as interview inquiry as well as thus delight percentage amongst your friends as well as colleagues. If y'all possess got whatever inquiry or feedback as well as thus delight drib a comment.

    Komentar

    Postingan populer dari blog ini

    Difference Betwixt Struts Validatorform Vs Validatoractionform - Interview Question

    How To Convert Inputstream To Byte Array Inwards Coffee - Two Examples

    Difference Betwixt Fileinputstream Together With Filereader Inwards Coffee | Inputstream Vs Reader