title: Hibernate 5.2.10: Unable to perform unmarshalling
body: <h1>Edit 5: Solved</h1>
  
  <p>The main problem was that I've used JDK 9, where the JAXB APIs are no longer on on the default class path. Here is <a href="https://stackoverflow.com/questions/43574426/how-to-resolve-java-lang-noclassdeffounderror-javax-xml-bind-jaxbexception-in-j">link where I've found solution</a>.</p>
  
  <hr>
  
  <p>I used hibernate version 4.3.6 from example tutorial and everything've worked good, but when I update version to 5.2.10 I have problem (I know that code responsible for getSessionFactory is different so I changed it).</p>
  
  <p>My first function:</p>
  
  <pre><code>private static SessionFactory getSessionFactory(){
      Configuration configuration = new Configuration().configure();
      StandardServiceRegistryBuilder builder = new StandardServiceRegistryBuilder()
              .applySettings(configuration.getProperties());
      SessionFactory sessionFactory = configuration.buildSessionFactory(builder.build());
      return sessionFactory;
  }
  </code></pre>
  
  <p>And my function in 5.2.10 version:</p>
  
  <pre><code>private static SessionFactory getSessionFactory(){
  
      StandardServiceRegistry registry;
      SessionFactory sessionFactory;
      registry = new StandardServiceRegistryBuilder().configure().build();
  
      MetadataSources sources = new MetadataSources(registry);
  
      Metadata metadata = sources.getMetadataBuilder().build();
  
      sessionFactory = metadata.getSessionFactoryBuilder().build();
      return sessionFactory;
  
  }
  </code></pre>
  
  <p>Exception:</p>
  
  <blockquote>
    <p>Exception in thread "main"
    org.hibernate.internal.util.config.ConfigurationException: Unable to
    perform unmarshalling at line number 0 and column 0 in RESOURCE
    hibernate.cfg.xml. Message: null</p>
  </blockquote>
  
  <p>and hibernate.cfg.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
          &lt;!DOCTYPE hibernate-configuration SYSTEM
  
  
  "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd"&gt;
  
  &lt;hibernate-configuration&gt;
      &lt;session-factory&gt;
          &lt;property name="hibernate.dialect"&gt;org.hibernate.dialect.PostgreSQL94Dialect&lt;/property&gt;
          &lt;property name="hibernate.connection.driver_class"&gt;org.postgresql.Driver&lt;/property&gt;
          &lt;property name="hibernate.connection.url"&gt;jdbc:postgresql://127.0.0.1:5432/postgres&lt;/property&gt;
          &lt;property name="hibernate.connection.username"&gt;postgres&lt;/property&gt;
          &lt;property name="hibernate.connection.password"&gt;123&lt;/property&gt;
          &lt;property name="hibernate.hbm2ddl.auto"&gt;update&lt;/property&gt;
          &lt;property name="show_sql"&gt;false&lt;/property&gt;
          &lt;property name="hibernate.current_session_context_class"&gt;thread&lt;/property&gt;
          &lt;mapping class="com.example.Item"/&gt;
      &lt;/session-factory&gt;
  &lt;/hibernate-configuration&gt;
  </code></pre>
  
  <p>Where is the problem? I've tried everything.</p>
  
  <h1>Edit: pom.xml</h1>
  
  <pre><code>  &lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;project xmlns="http://maven.apache.org/POM/4.0.0"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"&gt;
  &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
  
  &lt;groupId&gt;pl.example&lt;/groupId&gt;
  &lt;artifactId&gt;example&lt;/artifactId&gt;
  &lt;version&gt;1.0-SNAPSHOT&lt;/version&gt;
  
  &lt;build&gt;
      &lt;plugins&gt;
      &lt;plugin&gt;
          &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
          &lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt;
          &lt;version&gt;3.7.0&lt;/version&gt;
          &lt;configuration&gt;
              &lt;source&gt;1.8&lt;/source&gt;
              &lt;target&gt;1.8&lt;/target&gt;
          &lt;/configuration&gt;
      &lt;/plugin&gt;
      &lt;/plugins&gt;
  &lt;/build&gt;
  
  &lt;dependencies&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.postgresql&lt;/groupId&gt;
          &lt;artifactId&gt;postgresql&lt;/artifactId&gt;
          &lt;version&gt;42.1.4&lt;/version&gt;
      &lt;/dependency&gt;
  
      &lt;dependency&gt;
          &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
          &lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt;
          &lt;version&gt;3.7.0&lt;/version&gt;
      &lt;/dependency&gt;
  
  
      &lt;dependency&gt;
          &lt;groupId&gt;org.hibernate&lt;/groupId&gt;
          &lt;artifactId&gt;hibernate-core&lt;/artifactId&gt;
          &lt;version&gt;5.2.10.Final&lt;/version&gt;
      &lt;/dependency&gt;
  &lt;/dependencies&gt;
  </code></pre>
  
  <p></p>
  
  <h1>Edit 2</h1>
  
  <pre><code>public class HibernateUtil {
      private static final SessionFactory sessionFactory;
  static {
      try {
          StandardServiceRegistry standardRegistry =
                  new StandardServiceRegistryBuilder().configure("hibernate.cfg.xml").build();
          Metadata metaData =
                  new MetadataSources(standardRegistry).getMetadataBuilder().build();
          sessionFactory = metaData.getSessionFactoryBuilder().build();
      } catch (Throwable th) {
  
          System.err.println("Enitial SessionFactory creation failed" + th);
          throw new ExceptionInInitializerError(th);
  
      }
  }
  public static SessionFactory getSessionFactory() {
  
      return sessionFactory;
  
  }
  </code></pre>
  
  <p>}</p>
  
  <pre><code>@Entity
  @Table(name = "employee")
  public class Employee implements Serializable{
  
      @Id
      @GeneratedValue(strategy = GenerationType.IDENTITY)
      @Column(name="id")
      private int id;
  
      @Column(name="emp_name")
      private String empName;
  
      @Column(name="emp_address")
      private String empAddress;
  
      @Column(name="emp_mobile_nos")
      private String empMobileNos;
  
      public int getId() {
          return id;
      }
  
      public void setId(int id) {
          this.id = id;
      }
  
      public String getEmpName() {
          return empName;
      }
  
      public void setEmpName(String empName) {
          this.empName = empName;
      }
  
      public String getEmpAddress() {
          return empAddress;
      }
  
      public void setEmpAddress(String empAddress) {
          this.empAddress = empAddress;
      }
  
      public String getEmpMobileNos() {
          return empMobileNos;
      }
  
      public void setEmpMobileNos(String empMobileNos) {
          this.empMobileNos = empMobileNos;
      }
  
  }
  </code></pre>
  
  <p>Testing class.</p>
  
  <pre><code>  public class Test{
      public static void main(String[] args) throws Exception {
  
          SessionFactory sessFact = HibernateUtil.getSessionFactory();
          Session session = sessFact.getCurrentSession();
          org.hibernate.Transaction tr = session.beginTransaction();
          Employee emp = new Employee();
          emp.setEmpName("Deepak Kumar");
          emp.setEmpMobileNos("000000");
          emp.setEmpAddress("Delhi - India");
          session.save(emp);
          tr.commit();
          System.out.println("Successfully inserted");
          sessFact.close();
      }
  
  }
  </code></pre>
  
  <h1>Edit 3</h1>
  
  <pre><code>lis 17, 2017 11:54:50 PM org.hibernate.Version logVersion
  INFO: HHH000412: Hibernate Core {5.2.10.Final}
  lis 17, 2017 11:54:50 PM org.hibernate.cfg.Environment &lt;clinit&gt;
  INFO: HHH000206: hibernate.properties not found
  lis 17, 2017 11:54:50 PM org.hibernate.boot.jaxb.internal.stax.LocalXmlResourceResolver resolveEntity
  WARN: HHH90000012: Recognized obsolete hibernate namespace http://hibernate.sourceforge.net/hibernate-configuration. Use namespace http://www.hibernate.org/dtd/hibernate-configuration instead.  Support for obsolete DTD/XSD namespaces may be removed at any time.
  Enitial SessionFactory creation failedorg.hibernate.internal.util.config.ConfigurationException: Unable to perform unmarshalling at line number 0 and column 0 in RESOURCE hibernate.cfg.xml. Message: null
  Exception in thread "main" java.lang.ExceptionInInitializerError
      at pl.lostandfound.HibernateUtil.&lt;clinit&gt;(HibernateUtil.java:31)
      at pl.lostandfound.Test.main(Test.java:13)
  Caused by: org.hibernate.internal.util.config.ConfigurationException: Unable to perform unmarshalling at line number 0 and column 0 in RESOURCE hibernate.cfg.xml. Message: null
      at org.hibernate.boot.cfgxml.internal.JaxbCfgProcessor.unmarshal(JaxbCfgProcessor.java:133)
      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 pl.lostandfound.HibernateUtil.&lt;clinit&gt;(HibernateUtil.java:24)
      ... 1 more
  Caused by: javax.xml.bind.JAXBException
   - with linked exception:
  [java.lang.ClassNotFoundException: com.sun.xml.internal.bind.v2.ContextFactory]
      at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:241)
      at javax.xml.bind.ContextFinder.find(ContextFinder.java:477)
      at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:656)
      at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:599)
      at org.hibernate.boot.cfgxml.internal.JaxbCfgProcessor.unmarshal(JaxbCfgProcessor.java:122)
      ... 5 more
  Caused by: java.lang.ClassNotFoundException: com.sun.xml.internal.bind.v2.ContextFactory
      at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:582)
      at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:185)
      at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:496)
      at javax.xml.bind.ContextFinder.safeLoadClass(ContextFinder.java:594)
      at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:239)
      ... 9 more
  </code></pre>
  
  <h1>Edit 4</h1>
  
  <pre><code>    log4j:WARN No appenders could be found for logger (org.jboss.logging).
  log4j:WARN Please initialize the log4j system properly.
  log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
  Enitial SessionFactory creation failedorg.hibernate.internal.util.config.ConfigurationException: Could not locate cfg.xml resource [hibernate.cfg.xml]
  Exception in thread "main" java.lang.ExceptionInInitializerError
  </code></pre>