按照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进去了啊,
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进去了啊,
解决方案 »
- ibatis sqlmap 插入数据返回数据id问题
- 求转化以下XML文件的样式表写法
- MySql数据库主键设置问题
- 写个OA系数见工望有经验的CSDN网民指点
- hibernate\c3p0\hibernate.cfg.xml配置问题。
- 大家都来帮忙或学习呀,如何得到一个指定的月中有几周? 谢谢
- hibernate + struts 的update语句怎么写
- java怎么将excel表格数据导入数据库
- 高分求叫
- 给管理系统找个框架
- 100分求助一个简单的页面数据传入问题,谁可以帮忙下,非常感谢!!!
- 这是什么问题啊??????????????????????????????????????????????????????????????????????????
这句是默认hibernate.cfg.xml配置里面的pojo类
SessionFactory sf=new Configuration().configure().addClass(xxx.Student.class).buildSessionFactory();
这是手工配置xxx.Student.class类。正如楼上所说的,可能是你的映射类出问题了 ,自己检查检查。
最好有比较好的hibernate的项目代码,和教程,这样进步就快了