如何解决无法在行号 -1 处执行解组
我只想使用 hibernate 创建一个简单的 java 程序。我为此创建了一个 Maven 项目。
我创建了两个文件,一个是hibernate配置文件,另一个是app.java文件。
两个文件都在下面。
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration SYstem "https://www.hibernate-org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<properties name="connection.driver_class">com.MysqL.jdbc.Driver</properties>
<properties name="connection.url">jdbc:MysqL://localhost:3306/myhiber</properties>
<properties name="connection.username">root</properties>
<properties name="connection.password">root</properties>
<properties name="dialect">org.hibernate.dialect.MysqLDialect</properties>
<properties name="hbm2ddl">update</properties>
<properties name="show_sql">true</properties>
</session-factory>
</hibernate-configuration>
这是我的 hibernate.cfg.xml 文件
package com.tutorial.MavenProject;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
/**
* Hello World!
*
*/
public class App
{
public static void main( String[] args )
{
System.out.println( "Project World!" );
SessionFactory factory=new Configuration().configure("hibernate.cfg.xml").buildSessionFactory();
/*Configuration cfg=new Configuration();
cfg.configure("hibernate.cfg.xml");
SessionFactory factory=cfg.buildSessionFactory();*/
System.out.println(factory);
System.out.println(factory.isClosed());
}
}
这是我的 app.java 文件。
现在,当我构建并运行我的 app.java 时,我遇到了这样的异常。我是 hibernate 的初学者,所以不知道如何解决这个问题。
Project World!
May 01,2021 2:45:43 PM org.hibernate.Version logVersion
INFO: HHH000412: Hibernate ORM core version 5.4.31.Final
Exception in thread "main" org.hibernate.internal.util.config.ConfigurationException: Unable to perform unmarshalling at line number -1 and column -1 in RESOURCE hibernate.cfg.xml. Message: cvc-complex-type.2.4.a: Invalid content was found starting with element '{"http://www.hibernate.org/xsd/orm/cfg":properties}'. One of '{"http://www.hibernate.org/xsd/orm/cfg":property,"http://www.hibernate.org/xsd/orm/cfg":mapping,"http://www.hibernate.org/xsd/orm/cfg":class-cache,"http://www.hibernate.org/xsd/orm/cfg":collection-cache,"http://www.hibernate.org/xsd/orm/cfg":event,"http://www.hibernate.org/xsd/orm/cfg":listener}' is expected.
at org.hibernate.boot.cfgxml.internal.JaxbCfgProcessor.unmarshal(JaxbCfgProcessor.java:134)
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:258)
at com.tutorial.MavenProject.App.main(App.java:16)
Caused by: javax.xml.bind.UnmarshalException
- with linked exception:
[org.xml.sax.SAXParseException; cvc-complex-type.2.4.a: Invalid content was found starting with element '{"http://www.hibernate.org/xsd/orm/cfg":properties}'. One of '{"http://www.hibernate.org/xsd/orm/cfg":property,"http://www.hibernate.org/xsd/orm/cfg":listener}' is expected.]
at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.handleStreamException(UnmarshallerImpl.java:483)
at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:463)
at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal(UnmarshallerImpl.java:435)
at org.hibernate.boot.cfgxml.internal.JaxbCfgProcessor.unmarshal(JaxbCfgProcessor.java:127)
... 5 more
Caused by: org.xml.sax.SAXParseException; cvc-complex-type.2.4.a: Invalid content was found starting with element '{"http://www.hibernate.org/xsd/orm/cfg":properties}'. One of '{"http://www.hibernate.org/xsd/orm/cfg":property,"http://www.hibernate.org/xsd/orm/cfg":listener}' is expected.
at java.xml/com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:204)
at java.xml/com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.error(ErrorHandlerWrapper.java:135)
at java.xml/com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:396)
at java.xml/com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:327)
at java.xml/com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:284)
at java.xml/com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator$XSIErrorReporter.reportError(XMLSchemaValidator.java:511)
at java.xml/com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.reportSchemaError(XMLSchemaValidator.java:3587)
at java.xml/com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.handleStartElement(XMLSchemaValidator.java:1971)
at java.xml/com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.startElement(XMLSchemaValidator.java:829)
at java.xml/com.sun.org.apache.xerces.internal.jaxp.validation.ValidatorHandlerImpl.startElement(ValidatorHandlerImpl.java:570)
at com.sun.xml.bind.v2.runtime.unmarshaller.ValidatingUnmarshaller.startElement(ValidatingUnmarshaller.java:101)
at com.sun.xml.bind.v2.runtime.unmarshaller.InterningXmlVisitor.startElement(InterningXmlVisitor.java:75)
at com.sun.xml.bind.v2.runtime.unmarshaller.StAXEventConnector.handleStartElement(StAXEventConnector.java:261)
at com.sun.xml.bind.v2.runtime.unmarshaller.StAXEventConnector.bridge(StAXEventConnector.java:130)
at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:460)
... 7 more
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。