Hibernate Nullpointerexception Due To Infinite Inwards Hql Named Queries

If you lot are using Hibernate for implementing persistence layer inward Java together with JEE application from distich of years together with thus you lot would take maintain 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 unopen to piteous logging inward instance of Exception, which has caused me hours to debug a unproblematic 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 laissez passer the sack likewise take maintain a expect if you lot tin laissez passer the sack 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 you lot are using Hibernate for implementing persistence layer inward Java together with JEE application Hibernate NullPointerException due to Space inward HQL named queriesHQL query


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

After spending unopen to fourth dimension I establish that it was happening due to an extra infinite given afterward the colon inward the hibernate query (HQL). For instance nosotros had this every bit query String

select EMP_ADDRESS from Employee where EMP_ID = :  ID

Do you lot expose the extra space? Well it's non that slowly to location this sort of error. Now all you lot ask to produce to take away this NullPointerException is that to take away that extra white infinite from HQL query String i.e.

select EMP_ADDRESS from Employee where EMP_ID = : ID

So ever seat attending what you lot seat betwixt colon together with parameter inward named SQL queries. Of class Hibernate tin laissez passer the sack produce amend chore to render to a greater extent than information piece reporting fault instead of only throwing blank NullPointerException, which instead of giving unopen to clue tin laissez passer the sack real good mislead you lot into dissimilar direction. This is the work amongst whatever language, they tin laissez passer the sack non validate anything which is within String, wouldn't it survive amend if your HQL are likewise instruct validated at compile fourth dimension instead of runtime?

Further Learning
answer)
  • Difference betwixt get() together with load() method inward Hibernate? (answer)
  • 5 Spring together with 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 shape should non survive in conclusion inward Java? (answer)
  • 10 Hibernate Questions from Java Interviews (list)

  • Thanks for reading this article, if you lot similar this article together with interview query together with thus delight portion amongst your friends together with colleagues. If you lot take maintain whatever query or feedback together with thus delight drib a comment.

    Sumber https://javarevisited.blogspot.com/

    0 Response to "Hibernate Nullpointerexception Due To Infinite Inwards Hql Named Queries"

    Post a Comment

    Iklan Atas Artikel

    Iklan Tengah Artikel 1

    Iklan Tengah Artikel 2

    Iklan Bawah Artikel