当前位置: 代码迷 >> Java Web开发 >> 用ssh做了一个登录 出现上面的有关问题了
  详细解决方案

用ssh做了一个登录 出现上面的有关问题了

热度:6426   发布时间:2013-02-25 21:09:29.0
用ssh做了一个登录 出现下面的问题了
org.springframework.orm.hibernate3.HibernateQueryException: t_user is not mapped [from t_user where name=? and password=?]; nested exception is org.hibernate.hql.ast.QuerySyntaxException: t_user is not mapped [from t_user where name=? and password=?]
org.springframework.orm.hibernate3.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:660)
org.springframework.orm.hibernate3.HibernateAccessor.convertHibernateAccessException(HibernateAccessor.java:412)
org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:411)
org.springframework.orm.hibernate3.HibernateTemplate.executeWithNativeSession(HibernateTemplate.java:374)
org.springframework.orm.hibernate3.HibernateTemplate.find(HibernateTemplate.java:912)
org.springframework.orm.hibernate3.HibernateTemplate.find(HibernateTemplate.java:904)
web.dao.impl.UserDaoImpl.getAllUser(UserDaoImpl.java:24)
web.service.impl.UserServiceImpl.login(UserServiceImpl.java:27)
web.action.LoginAction.execute(LoginAction.java:53)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
java.lang.reflect.Method.invoke(Method.java:601)

LoginAction里的代码:

public String execute() {
User user = new User();
user.getName();
user.getPassword();
//System.out.println(user.getId()+"1");
if (userService.login(user)) {

return "YES";
}
//System.out.println(user.getName()+"****"+user.getPassword());
return "NO";
}
LoginDAOImp里的代码:


public boolean getAllUser(User user) {
System.out.println(user.getName()+"3");


String hql = "from t_user where name=? and password=?";
Object []obj ={user.getName(),user.getPassword()};

List list = super.getHibernateTemplate().find(hql);

if(list.size()>0){
System.out.println("成功!");
return true;
}else{
return false;
}
}

------解决方案--------------------------------------------------------
很明显t_user没有和数据库映射好,配置文件没配?还是粗心没配好?
用注解的话,类上加个@Entity,主键上加个@Id 就ok 了
org.springframework.orm.hibernate3.HibernateQueryException: t_user is not mapped [from t_user where name=? and password=?]; nested exception is org.hibernate.hql.ast.QuerySyntaxException: t_user is not mapped [from t_user where name=? and password=?]
------解决方案--------------------------------------------------------
String hql = "from t_user where name=? and password=?";
这是sql,不是hql
HQL是这样的
String hql = "from User user where user.name=? and user.password=?";
------解决方案--------------------------------------------------------
应该是hql语句,hibernate是对对象操作,
------解决方案--------------------------------------------------------
映射 存在问题 表和映射bean不对应! 检查你的bean
------解决方案--------------------------------------------------------
数据库的表存在映射的问题。
  相关解决方案