dao层
@SuppressWarnings("unchecked")
public List<M_REPORTUSER> findVo(String hql) throws Exception {
return this.getHibernateTemplate().find(hql);
}
service层
public M_REPORTUSER findUserByUserId(String userid) throws Exception {
M_REPORTUSER us = new M_REPORTUSER();
try {
List<M_REPORTUSER> ls = new ArrayList<M_REPORTUSER>();
String hql = " from m_reportuser where userid = "+userid+"";
ls = userDao.getUserByhql(hql);
if(!ls.isEmpty()&&ls.size()>0){
us = ls.get(0);
}
} catch (Exception e) {
throw e;
}
return us;
}
报错:org.springframework.orm.hibernate3.HibernateQueryException: m_reportuser is not mapped
原因:出现这个错误的根本原因是hql语法里面是POJO对象而不是table.所以把table改为和POJO一模一样就可以了
String hql = " from M_REPORTUSER where userid = "+userid+"";