用hibernateTemplate().find()方法时出现以下错误
org.springframework.orm.hibernate3.HibernateQueryException: Manager is not mapped [from Manager]; nested exception is org.hibernate.hql.ast.QuerySyntaxException: Manager is not mapped [from Manager]
纠结了好长时间,上网一查才知道好多人出现过相同问题,原因一般有:
1,hbm.xml 没在beans.xml中配置
<property name="packagesToScan">
<list><value>com.fzb.shop.entity</value></list>
</property>
2,find()方法中的类名大小写
因为Hibernate是对类查询的
在hql="select * from user u where u.username='"+username+"' and u.password='"+password+"'中,
user是数据库中的表,而user对应的类是User.java,现在只需要将from user改为from User,同时不用在出现select *即可
3.User.java中 Entity包引用是否出错。
package com.kent.ssh.model;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
@Entity
public class User {
private int id;
private String username;
private String password;
@Id
@GeneratedValue
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
}