spring+hibernate出现未知的实体异常

来源:百度知道 编辑:UC知道 时间:2024/05/06 02:46:55
下面是我写的junit方法 save方法能通过,findById就出现了未知的实体异常,怎么回事?
public void testSave(){
ApplicationContext ac;
ac=new ClassPathXmlApplicationContext("applicationContext.xml");
DeptbillDAO deptDao=(DeptbillDAO)ac.getBean("DeptbillDAO");
Deptbill dept=new Deptbill();
dept.setDetpName("销售部");
dept.setManager("程胜");
dept.setValid((byte)0);
deptDao.save(dept);
}

public void testFindById() {
ApplicationContext ac;
ac=new ClassPathXmlApplicationContext("applicationContext.xml");
DeptbillDAO deptDao=(DeptbillDAO)ac.getBean("DeptbillDAO");
System.out.println(deptDao.findById(1));
}
在默认路径 src下~
为什么第一个能通过 第二个就不能呢?

public Deptbill findById( java.lang.Integer id) {
log.debug("getting Deptbill instance with id: " + id);
try {
Deptbill instance = (Deptbill) getHibernateTe

Deptbill instance = (Deptbill) getHibernateTemplate()
.get(Deptbill, id);
改成这样试试
或者你没有id为1那一行?

Deptbill instance = (Deptbill) getHibernateTemplate()
.get("com.cqeec.dao.Deptbill", id);

这句错了。

应该是:
Deptbill instance = (Deptbill) getHibernateTemplate()
.get(Deptbill.class, id);

还有,数据库中id必须是主键