一样的程序,用了5.2版本的hibernate的jar包就出错
一样的程序,老程序用老师给的jar包跑没出错,下了5.2版本的hibernate的jar包,想试试新版本创建SessionFactory的方式就一直报错。
老程序:
Configuration c = new Configuration().configure();
ServiceRegistry serviceRegistry = new ServiceRegistryBuilder()
.applySettings(c.getProperties()).buildServiceRegistry();
SessionFactory sf = c.buildSessionFactory(serviceRegistry);
Session s = sf.openSession();
Transaction transaction = s.beginTransaction();
新程序:
Configuration c = new Configuration().configure();
ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().applySettings(c.getProperties()).build();
SessionFactory sf = c.buildSessionFactory(serviceRegistry);
Session s = sf.openSession();
Transaction transaction = s.beginTransaction();
错误信息:
java.lang.NoClassDefFoundError:javax/xml/bind/JAXBException
去网上查说是缺这个jar包,下载导入后还是会报这个错
org.hibernate.internal.util.config.ConfigurationException:Unable to perform unmarshalling at line number 0 and column 0 in
RESOURCE hibernate.cfg.xml. Message:null
同时控制台会输出:
1月 26, 2018 11:44:32 上午 org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {5.2.12.Final}
1月 26, 2018 11:44:32 上午 org.hibernate.cfg.Environment <clinit>
INFO: HHH000206: hibernate.properties not found
使用的jar包如下,jaxb-api-2.2.12.jar是后面添加进去的那个jar包