-1

Error message: Exception in thread "main" org.hibernate.HibernateException: Error accessing stax stream This link did not help me solve my issue. I get the following error.What should I do?

 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

The following code is my 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>

Please help me solve this issue. Thank you in advance.

Lejdi Prifti
  • 29
  • 1
  • 13
  • Could you give your pom.xml file and tell us what is the server your run your application on ? – wargre Jul 26 '18 at 15:14

1 Answers1

0

I usually get this error on project that have wrong XML parser in classpath.

Unfortunately, project are usually bloated by a lot of XML parser. Just clean them.

You can check

  • xml-apis jar. Take only the version 2.7.1
  • xerces / xercesImpl the same: version 2.7.1
  • Saxon / Saxon9 : If you use it with java8: you need to have a version 9.7 minimum
wargre
  • 4,575
  • 1
  • 19
  • 35