配置hibernate 5.0.1和MySQL时出错
我在使用MySQL配置hibernate 5.0.1时遇到问题,我在这里看到一些问题,说明版本4中存在错误,我不确定天气这是同一个错误还是我做错了什么。
这是我的配置文件hibernate.cfg.xml
com.mysql.jdbc.Driver jdbc:mysql://localhost:3306/hibernatedb root 1 org.hibernate.dialect.MySQLDialect thread org.hibernate.cache.internal.NoCacheProvider true update
这是我的sessionfactory代码
SessionFactory sessionfactory = new Configuration().configure().buildSessionFactory(); Session session = sessionfactory.openSession(); session.beginTransaction(); session.save(user); session.getTransaction().commit();
这是错误日志。
Exception in thread "main" org.hibernate.internal.util.config.ConfigurationException: Unable to perform unmarshalling at line number 12 and column 63 in RESOURCE hibernate.cfg.xml. Message: cvc-elt.1: Cannot find the declaration of element 'hibernate-configuration'. at org.hibernate.boot.cfgxml.internal.JaxbCfgProcessor.unmarshal(JaxbCfgProcessor.java:133) at org.hibernate.boot.cfgxml.internal.JaxbCfgProcessor.unmarshal(JaxbCfgProcessor.java:65) at org.hibernate.boot.cfgxml.internal.ConfigLoader.loadConfigXmlResource(ConfigLoader.java:55) at org.hibernate.boot.registry.StandardServiceRegistryBuilder.configure(StandardServiceRegistryBuilder.java:163) at org.hibernate.cfg.Configuration.configure(Configuration.java:259) at org.hibernate.cfg.Configuration.configure(Configuration.java:245) at org.cypher.hibernate.HibernateTest.main(HibernateTest.java:15) Caused by: javax.xml.bind.UnmarshalException
谢谢。
所以这是解决方案。
更换
同
并在文件顶部添加以下代码。
同样在配置文件中将
替换为
尝试在hibernate.cfg.xml的开头插入以下内容: