日期:2014-05-18  浏览次数:20668 次

hibernate初学一问
按照hibernate3自带的例子和很多教程上写的:
SessionFactory   sf=new   Configuration().configure().buildSessionFactory();
Session   session=sf.getCurrentSession();或Session   session=sf.openSession();
后面运行下面代码时,提示Unknown   entity:   xxx.Student
session.beginTransaction();
Student   stu=new   Student();
stu.setName( "test ");
stu.setAge(20);
session.save(stu);
session.getTransaction().commit();
session.close();

如果改成这样写就可以
SessionFactory   sf=new   Configuration().configure().addClass(xxx.Student.class).buildSessionFactory();
Session   session=sf.openSession();

xxx.Student这个类已经import进去了啊,

------解决方案--------------------
你的hibernate.cfg.xml文件里是否已经加了student.hbm.xml文件了?
------解决方案--------------------
比如: <mapping resource= "student.hbm.xml " />