如何排序或解决 Hibernate XML 错误?线程“main”中的异常 org.hibernate.HibernateException

问题描述 投票:0回答:1

当我运行主类时,编译器会出现一些错误,错误写在下面。 这很难排序,我总共浪费了四个多小时。 这是 hibernate.cfg.xml 文件

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
    "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
    <property name="connection.driver_class">com.mysql.jdbc.Driver</property>
    <property name="connection.url">jdbc:mysql://localhost:3306/myhiber</property>
    <property name="connection.username">root</property>
    <property name="connction.password">Kunal@1234@</property>
    <property name="dialect">org.hibernate.dialect.MySQLDialect</property>
    <property name="hbm2ddl.auto">update</property>
    <property name="show_sql">true</property>
</session-factory>

</hibernate-configuration>

这是主课

package com.hona.hoja;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;


public class App 
{
    public static void main( String[] args )
    {
        System.out.println( "Project Started..." );
        Configuration cfg = new Configuration();
        cfg.configure("hibernate.cfg.xml");
        SessionFactory factory = cfg.buildSessionFactory();
        System.out.println(factory);
        System.out.println(factory.isClosed());
}
}

我遇到以下错误,我该如何解决?

INFO: HHH000412: Hibernate ORM core version 5.5.4.Final
Exception in thread "main" org.hibernate.HibernateException: Error accessing stax stream
    at org.hibernate.boot.cfgxml.internal.JaxbCfgProcessor.unmarshal(JaxbCfgProcessor.java:108)
    at org.hibernate.boot.cfgxml.internal.JaxbCfgProcessor.unmarshal(JaxbCfgProcessor.java:66)
    at org.hibernate.boot.cfgxml.internal.ConfigLoader.loadConfigXmlResource(ConfigLoader.java:57)
    at org.hibernate.boot.registry.StandardServiceRegistryBuilder.configure(StandardServiceRegistryBuilder.java:254)
    at org.hibernate.cfg.Configuration.configure(Configuration.java:260)
    at com.hona.hoja.App.main(App.java:13)
Caused by: javax.xml.stream.XMLStreamException: ParseError at [row,col]:[3,64]
Message: White spaces are required between publicId and systemId.
    at java.xml/com.sun.org.apache.xerces.internal.impl.XMLStreamReaderImpl.next(XMLStreamReaderImpl.java:652)
    at java.xml/com.sun.xml.internal.stream.XMLEventReaderImpl.peek(XMLEventReaderImpl.java:277)
    at org.hibernate.boot.cfgxml.internal.JaxbCfgProcessor.unmarshal(JaxbCfgProcessor.java:104)
    ... 5 more

我将考虑使用 XML 格式的文件 hibernate.cfg.xml 在我的示例中指定所需的 Hibernate 属性。大多数属性都采用默认值,除非确实需要,否则不需要在属性文件中指定它们。该文件保存在应用程序类路径的根目录中。

java xml eclipse hibernate jdbc
1个回答
0
投票

错误消息甚至告诉您有问题的行(第 3 行)。

我自己使用注释,但是你的

DOCTYPE
比我在网上找到的示例文件少了一个参数。

<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
© www.soinside.com 2019 - 2024. All rights reserved.