• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Hibernate Query Language where clause

 
hari ann
Greenhorn
Posts: 11
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

I am having below query in my program. I am getting the error while running this


SQL Error: 1054, SQLState: 42S22
Unknown column 'usid' in 'where clause'

DynaValidatorActionForm myform=(DynaValidatorActionForm) form;
String usid=(String) myform.get("userid");
String qry="Select password from User as user where user.userid=usid";
Query query = session.createQuery(qry);
List l= query.list();
System.out.println(l.get(0));



<tr>
<td >User ID*</td>
<td><html:text property="userid"/>/td>
</tr>
<tr>
<td >Password*</td>
<td><html:password property="password" /></td>
/tr>



public class User {

private long userNo;
private String userid;
private String password;

public String getPassword() {
return password;
}

public void setPassword(String password) {
this.password = password;


public String getUserid() {
return userid;
}

public void setUserid(String userid) {
this.userid = userid;
}

public String getPassWord(String userid){
return password;
}
}


<hibernate-mapping>
<class name="com.example.User" table="user">
<id column="uno" name="userNo">
<generator class="increment"/>
</id>
<property column="uid" name="userid"/>
<property column="upwd" name="password"/>
<
</hibernate-mapping>
 
Vikas Kapoor
Ranch Hand
Posts: 1374
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

usid is a variable. It can't be used like this.
I ain't sure but try,

or
 
hari ann
Greenhorn
Posts: 11
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried with the below one. But this time i am getting diffrent type of exception. Can you please help on this

org.hibernate.QueryException: Not all named parameters have been set: [uid] [select us.password from User us where us.userid = :uid]s

User user =(User) factory.getBean("user");
String uid=(String)form.get("userid");
String hql="select us.password from User us where us.userid = :uid";
Query query=session.createQuery(hql);
String dbpwd = (String) query.uniqueResult();
if(dbpwd.equals(uid)){
System.out.println(dbpwd);
return true;
}
else
{
return false;
}
}
 
Thirumurugan Sivaji
Greenhorn
Posts: 20
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Remodify your code as follows,

User user =(User) factory.getBean("user");
String hql="select us.password from User us where us.userid = :uid";
Query query=session.createQuery(hql);
query.setString("uid",(String)form.get("userid"));

or

User user =(User) factory.getBean("user");
String hql="select us.password from User us where us.userid = ?";
Query query=session.createQuery(hql);
query.setString(0,(String)form.get("userid"));
 
hari ann
Greenhorn
Posts: 11
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you to all for your help

It has worked now.
 
Vikas Kapoor
Ranch Hand
Posts: 1374
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're Welcome Susmita!
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic