错误消息:线程“main”org.hibernate.HibernateException 中出现异常:访问 stax 流时出错

Ani*_*ika 5 java mysql eclipse hibernate

I\xc2\xb4m 尝试使用 hibernate 创建 MySQL 数据库表,但收到以下错误消息:

\n\n
Exception in thread "main" org.hibernate.HibernateException: Error accessing stax stream\n    at org.hibernate.boot.cfgxml.internal.JaxbCfgProcessor.unmarshal(JaxbCfgProcessor.java:107)\n    at org.hibernate.boot.cfgxml.internal.JaxbCfgProcessor.unmarshal(JaxbCfgProcessor.java:65)\n    at org.hibernate.boot.cfgxml.internal.ConfigLoader.loadConfigXmlResource(ConfigLoader.java:57)\n    at org.hibernate.boot.registry.StandardServiceRegistryBuilder.configure(StandardServiceRegistryBuilder.java:163)\n    at org.hibernate.cfg.Configuration.configure(Configuration.java:259)\n    at com.anika.hibernate.Main.main(Main.java:18)\nCaused by: javax.xml.stream.XMLStreamException: ParseError at [row,col]:[2,34]\n
Run Code Online (Sandbox Code Playgroud)\n\n

这个答案并不能解决我的问题:Errorconnectingwithdatabaseusinghibernate

\n\n

线程“main”org.hibernate.HibernateException 中出现异常:访问 stax 流时出错

\n\n

这是我的 Main.java 文件:

\n\n
package com.anika.hibernate;\n\nimport org.hibernate.Session;\nimport org.hibernate.SessionFactory;\nimport org.hibernate.cfg.Configuration;\n\n\n\npublic class Main {\n\n    public static void main(String[] args){\n\n    Student_Info student = new Student_Info();\n\n    student.setName("Anika");\n    student.setRollNo(1);\n\n    SessionFactory sessionFactory = new Configuration().configure("hibernate.cfg.xml").buildSessionFactory();   \n    Session session = sessionFactory.openSession();\n    session.beginTransaction();\n\n    session.save(student);\n\n    session.getTransaction().commit();\n    session.close();\n    sessionFactory.close();\n\n\n    }   \n\n}\n
Run Code Online (Sandbox Code Playgroud)\n\n

我的 hibernate.cfg.xml:

\n\n
<?xml version=\'1.0\' encoding=\'utf-8\'?>\n<DOCTYPE hibernate-configuration PUBLIC\n        "-//Hibernate/Hibernate Configuration DTD 3.0//EN"\n        "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">\n\n<!--\n  ~ Hibernate, Relational Persistence for Idiomatic Java\n  ~\n  ~ License: GNU Lesser General Public License (LGPL), version 2.1 or later.\n  ~ See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.\n  -->\n<hibernate-configuration\n\n  <session-factory>\n    <!-- Database connection settings -->\n    <property name="connection.driver_class">com.mysql.jdbc.Driver</property>\n    <property name="connection.url">jdbc:mysql://localhost:3306/hibernatetutorials</property>\n    <property name="connection.username">root</property>\n    <property name="connection.password"></property>\n\n    <!-- JDBC connection pool (use the built-in) -->\n    <property name="connection.pool_size">1</property>\n\n    <!-- SQL dialect -->\n    <property name="dialect">org.hibernate.dialect.MySQLDialect</property>\n\n\n    <!-- Disable the second-level cache  -->\n    <property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>\n\n    <!-- Echo all executed SQL to stdout -->\n    <property name="show_sql">true</property>\n\n    <!-- Drop and re-create the database schema on startup -->\n    <property name="hbm2ddl.auto">create</property>\n    <mapping class="com.anika.hibernate.Stundent_Info"/>\n  </session-factory>\n</hibernate-configuration>\n
Run Code Online (Sandbox Code Playgroud)\n\n

感谢您的帮助

\n

v.l*_*nev 0

您需要关闭标签<hibernate-configuration

<hibernate-configuration>

!中没有该字符DOCTYPE

<DOCTYPE hibernate-configuration PUBLIC
        "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
        "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
Run Code Online (Sandbox Code Playgroud)

应该

<!DOCTYPE hibernate-configuration PUBLIC
    "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
    "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
Run Code Online (Sandbox Code Playgroud)