gpt4 book ai didi

java - 错误消息 : Exception in thread "main" org. hibernate.HibernateException:访问 stax 流时出错

转载 作者:行者123 更新时间:2023-11-29 02:17:13 25 4
gpt4 key购买 nike

我正在尝试使用 hibernate 创建 MySQL 数据库表,但我收到此错误消息:

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

这个答案没有解决我的问题:Error connecting with database using hibernate

Exception in thread "main" org.hibernate.HibernateException: Error accessing stax stream

这是我的 Main.java 文件:

package com.anika.hibernate;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;



public class Main {

public static void main(String[] args){

Student_Info student = new Student_Info();

student.setName("Anika");
student.setRollNo(1);

SessionFactory sessionFactory = new Configuration().configure("hibernate.cfg.xml").buildSessionFactory();
Session session = sessionFactory.openSession();
session.beginTransaction();

session.save(student);

session.getTransaction().commit();
session.close();
sessionFactory.close();


}

}

我的 hibernate.cfg.xml:

<?xml version='1.0' encoding='utf-8'?>
<DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">

<!--
~ Hibernate, Relational Persistence for Idiomatic Java
~
~ License: GNU Lesser General Public License (LGPL), version 2.1 or later.
~ See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
-->
<hibernate-configuration

<session-factory>
<!-- Database connection settings -->
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.url">jdbc:mysql://localhost:3306/hibernatetutorials</property>
<property name="connection.username">root</property>
<property name="connection.password"></property>

<!-- JDBC connection pool (use the built-in) -->
<property name="connection.pool_size">1</property>

<!-- SQL dialect -->
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>


<!-- Disable the second-level cache -->
<property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>

<!-- Echo all executed SQL to stdout -->
<property name="show_sql">true</property>

<!-- Drop and re-create the database schema on startup -->
<property name="hbm2ddl.auto">create</property>
<mapping class="com.anika.hibernate.Stundent_Info"/>
</session-factory>
</hibernate-configuration>

谢谢你的帮助

最佳答案

我遇到了同样的问题。事实证明系统无法从提供的 url 访问 hibernate-configuration-3.0.dtd。

    <DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">

所以,我从本地系统引用了它。

    <!DOCTYPE hibernate-configuration SYSTEM
"classpath://org/hibernate/hibernate-configuration-3.0.dtd">

对我来说效果很好。希望对您有所帮助!

关于java - 错误消息 : Exception in thread "main" org. hibernate.HibernateException:访问 stax 流时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37588091/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com