org.hibernate.QueryParameterException: could not locate named parameter [userId]

浪尽此生 提交于 2019-12-06 09:49:42
JamesB

The problem is that Hibernate cannot find your setter for the field userId. You have defined it like this:

public void setUser_id(String userId) { 
    this.userId = userId;
} 

It should be:

public void setUserId(String userId) { 
    this.userId = userId;
} 

Hibernate map your database by your variable name. So you have;

userId;

but in your query you have

user_id

You need to use userId not user_id.

And exception clearly says you provided the wrong parameter.

Ankit

Check if it is typo error

loginId = (String) session.createQuery("select user_id from com.project.model.Login where user_id=:userId and password=:password") .**setParameter("userId",userId)**.setParameter("password", password).list().toString();


loginId = (String) session.createQuery("select user_id from com.project.model.Login where user_id=:userId and password=:password") .**setParameter("user_id",userId)**.setParameter("password", password).list().toString();
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!