2.解决方案
可能一:将*.hbm.xml中的class标签中的name写为类所在路径。
错误时为:
<class name="Student" table="STUDENTS">
修改后为:
<class name="org.hibernate.model.Student" table="STUDENTS">
可能二:可能是获取sessionFactory方式有问题
// 创建配置对象
Configuration config = new Configuration().configure();
// 创建服务注册对象(hibernate4.35之后该方法就不能再获取到实体信息了)
StandardServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder()
.applySettings(config.getProperties()).build();
// 创建会话工厂对象
sessionFactory = config.buildSessionFactory(serviceRegistry);
// 创建会话
session = sessionFactory.openSession();
// 开启事务
transaction = session.beginTransaction();
hibernate4.35之后sessionFactory获取方式
// 创建会话工厂对象
sessionFactory = new Configuration().configure().buildSessionFactory();
// 创建会话
session = sessionFactory.openSession();
// 开启事务
transaction = session.beginTransaction();
我是使用Hibernate Tools 新生成了DAO文件,因为接入了Spring,没有将
private final SessionFactory sessionFactory = getSessionFactory();
改为
ApplicationContext ctx=new ClassPathXmlApplicationContext("applicationContext.xml");
SessionFactory sessionFactory=(SessionFactory) ctx.getBean("sessionFactory");
https://www.cnblogs.com/jinjiyese153/p/6902785.html#undefined