为什么我收到此错误访问stax流时出错

时间:2018-07-26 02:51:25

标签: java xml hibernate hibernate-mapping hibernate.cfg.xml

Error message: Exception in thread "main" org.hibernate.HibernateException: Error accessing stax stream此链接没有帮助我解决问题。我收到以下错误。该怎么办?

 Jul 26, 2018 4:44:24 AM org.hibernate.Version logVersion
 INFO: HHH000412: Hibernate Core {5.3.3.Final}
 Jul 26, 2018 4:44:24 AM org.hibernate.cfg.Environment <clinit>
 INFO: HHH000206: hibernate.properties not found
 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$2.run(ConfigLoader.java:62)
at org.hibernate.boot.cfgxml.internal.ConfigLoader$2.run(ConfigLoader.java:53)
at org.hibernate.boot.cfgxml.internal.ConfigLoader.loadConfigXmlResource(ConfigLoader.java:79)
at org.hibernate.boot.registry.StandardServiceRegistryBuilder.configure(StandardServiceRegistryBuilder.java:165)
at org.hibernate.cfg.Configuration.configure(Configuration.java:258)
at com.internship.java.HibernateTest.main(HibernateTest.java:16)
Caused by: javax.xml.stream.XMLStreamException: ParseError at [row,col]:[8,1]
Message: Content is not allowed in prolog.
    at com.sun.org.apache.xerces.internal.impl.XMLStreamReaderImpl.next(XMLStreamReaderImpl.java:604)
    at com.sun.xml.internal.stream.XMLEventReaderImpl.peek(XMLEventReaderImpl.java:276)
    at org.hibernate.boot.cfgxml.internal.JaxbCfgProcessor.unmarshal(JaxbCfgProcessor.java:103)
    ... 7 more

以下代码是我的hibernate.cfg.xml

  <?xml version="1.0" encoding="UTF-8"?>

  <!-- ~ 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>. -->

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

   -<hibernate-configuration>


   -<session-factory>

    <!-- Database connection settings -->


      <property 
     name="connection.driver_class">org.postgresql94.Driver</property>

   <property 
   name="connection.url">jdbc:postgresql://localhost:5432/postgres</property>

     <property name="connection.username">postgres</property>

   <property name="connection.password">password</property>

    <!-- JDBC connection pool (use the built-in) -->


    <property name="connection.pool_size">1</property>

      <!-- SQL dialect -->


      <property 
    name="dialect">org.hibernate.dialect.PostgreSQLDialect</property>

     <!-- Disable the second-level cache -->


    <property 


    name="cache.provider_class">org.hibernate.cache.internal.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 resource="org/hibernate/tutorial/hbm/Event.hbm.xml"/>
         <mapping class="com.test.java.UserDetails"/>

      </session-factory>

       </hibernate-configuration>

请帮助我解决此问题。预先谢谢你。

1 个答案:

答案 0 :(得分:0)

我通常在类路径中具有错误XML解析器的项目上遇到此错误。

不幸的是,许多XML解析器通常会使项目肿。只是清洁它们。

您可以检查

  • xml-apis jar。仅采用版本2.7.1
  • xerces / xerces表示相同:版本2.7.1
  • Saxon / Saxon9:如果将其与java8一起使用:您需要的最低版本为9.7