0

I am new in hibernate. When sending the static parameter in HQL query its working fine. When sending in setParameter Method it's giving null pointer exception. Please help what I am doing wrong in it.

        /** HQL Query **/
         String hql = "FROM MUser mUser where mUser.uEmail = :email AND mUser.uPassword = :password";
           Query query = getCurrentSession().createQuery(hql);
           query.setParameter("email", "xyz@fsndk.com");
           query.setParameter("password", "12345678");

            MUser muser = (MUser) query.uniqueResult();

Model class

/** Mapping Class **/

@Entity
@Table(name="tbl_users")
public class MUser implements Serializable {


    @Id
    @GeneratedValue(strategy=GenerationType.AUTO)
    int uId;

    String uName;

    String uMobile;
    String uAddress;
    String uEmail;
    String uPassword;

...

}

Error coming

org.springframework.web.util.NestedServletException: Request processing failed; nested exception is java.lang.NullPointerException
    org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:973)
    org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:863)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:648)
    org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:837)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393)
Harpz
  • 183
  • 1
  • 12
  • a nested exception should be included in the stacktrace. – AxelH Nov 02 '17 at 12:17
  • from my knowledge Select is not needed to write Select Query in HQL @L – Harpz Nov 02 '17 at 12:19
  • Can you provide the stacktrace with the root cause – Tom Nov 02 '17 at 12:38
  • The problem is that when i am sending in the setParameter() method its returning null so all error coming from that. But idk why returning null – Harpz Nov 02 '17 at 13:00
  • What I meant is who causes the nullpointer – Tom Nov 02 '17 at 13:06
  • String hql = "FROM MUser mUser where mUser.uEmail = 'xyz@fsnk.com 'AND mUser.uPassword = '12345678'"; Query query = getCurrentSession().createQuery(hql); whenr i am writing this code its returning value when i using setParameter() method its returning null – Harpz Nov 02 '17 at 13:09
  • @Tom I now what is NullPointerException – Harpz Nov 02 '17 at 13:11
  • I doubt it. If you would actually know that, then this question wouldn't exist. – Tom Nov 02 '17 at 13:12
  • @Tom My Hibernate Query returning Null object the problem is that when I am using in setParameter() value. – Harpz Nov 02 '17 at 13:19
  • So the question is why createQuery returns null. I can't detect an error in the hql string so I assume it is somewhere else. – Tom Nov 02 '17 at 13:57
  • String hql = "FROM MUser mUser where mUser.uEmail = 'xyz@fajs.com' AND mUser.uPassword = '12345678'"; – Harpz Nov 02 '17 at 14:27
  • when i am sending this its working fine – Harpz Nov 02 '17 at 14:28

0 Answers0