按照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进去了啊,

解决方案 »

  1.   

    你的hibernate.cfg.xml文件里是否已经加了student.hbm.xml文件了?
      

  2.   

    比如:<mapping resource="student.hbm.xml" />
      

  3.   

    SessionFactory sf=new Configuration().configure().buildSessionFactory();
    这句是默认hibernate.cfg.xml配置里面的pojo类
    SessionFactory sf=new Configuration().configure().addClass(xxx.Student.class).buildSessionFactory();
    这是手工配置xxx.Student.class类。正如楼上所说的,可能是你的映射类出问题了 ,自己检查检查。
      

  4.   

    现在清楚了,是在配置文件里加上就行了初学hibernate,感觉用不上手,把它当做jdbc的简单封装了,不知怎么才能用到它的精髓。
    最好有比较好的hibernate的项目代码,和教程,这样进步就快了