我在利用hibernate的查询功能时总是出现org.hibernate.hql.ast.QuerySyntaxException: unexpected token异常,程序代码如下所示:
Employee employee = new Employee();
try{
Query query = session.createQuery( "form Employee as s where s.username = ? and s.password = ? ");
query.setString(0, username);
query.setString(1, password);
}
tx.commit();
HibernateSessionFactory.closeSession();
}catch (HibernateException re) {
re.printStackTrace();
tx.rollback();
return false;
}
异常总是在 Query query = session.createQuery( "form Employee as s where s.username = ? and s.password = ? ");
处发生,请问高手这句话该怎么改正?非常盼望得到高手的指点,谢谢!
其中Employee类如下:
public class Employee implements java.io.Serializable {
private Integer id;
private String username;
private String password;
public Employee() {
}
// Property accessors
public Integer getId() {
return this.id;
}
public void setId(Integer id) {
this.id = id;
}
public String getUsername() {
return this.username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return this.password;
}
public void setPassword(String password) {
this.password = password;
}
}
------解决方法--------------------------------------------------------
改为
Query query = session.createQuery( "form Employee as s where s.username = username and s.password = username ");
------解决方法--------------------------------------------------------
你的from都写成form了,看清楚!