title: Hibernate 5: sessionFactory is null
body: <p>Im getting a null value for <code>sessionFactory</code> variable at this line:</p>
  
  <pre><code>sessionFactory = new MetadataSources( registry ).buildMetadata().buildSessionFactory();
  </code></pre>
  
  <p>This is the whole class:</p>
  
  <pre><code>import javax.imageio.spi.ServiceRegistry;
  import javax.transaction.Transaction;
  
  import org.hibernate.Session;
  import org.hibernate.SessionFactory;
  import org.hibernate.boot.MetadataSources;
  import org.hibernate.boot.registry.StandardServiceRegistry;
  import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
  import org.hibernate.cfg.Configuration;
  
  import ch.makery.model.Employee;  
  
  public class HelloWorld {
      protected void setUp() throws Exception {
      }
  
      public static void main(String[] args) {
  
          SessionFactory sessionFactory = null;
  
          // A SessionFactory is set up once for an application!
          final StandardServiceRegistry registry = new StandardServiceRegistryBuilder()
                  .configure() // configures settings from hibernate.cfg.xml
                  .build();
          try {
              sessionFactory = new MetadataSources( registry ).buildMetadata().buildSessionFactory();
          }
          catch (Exception e) {
              // The registry would be destroyed by the SessionFactory, but we had trouble building the SessionFactory
              // so destroy it manually.
              StandardServiceRegistryBuilder.destroy( registry );
          }
  
          Session session = sessionFactory.openSession();
          //employee = new Employee();
  
         session.beginTransaction();
         session.save(new Employee());
         session.getTransaction().commit();
         session.close();
      }
  }
  </code></pre>
  
  <p>This is my Hibernate related files:</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;!DOCTYPE hibernate-configuration PUBLIC
          "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
          "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"&gt;
  &lt;hibernate-configuration&gt;
      &lt;session-factory&gt;
          &lt;property name="hibernate.connection.driver_class"&gt;com.mysql.jdbc.Driver&lt;/property&gt;
          &lt;property name="hibernate.connection.password"&gt;manolete&lt;/property&gt;
          &lt;property name="hibernate.connection.url"&gt;jdbc:mysql://localhost:3306/employee&lt;/property&gt;
          &lt;property name="hibernate.connection.username"&gt;root&lt;/property&gt;
          &lt;property name="cache.provider_class"&gt;org.hibernate.cache.internal.NoCacheProvider&lt;/property&gt;
          &lt;property name="hbm2ddl.auto"&gt;create&lt;/property&gt;
          &lt;mapping resource="src/ch/makery/model/Employee.hbm.xml" /&gt;
      &lt;/session-factory&gt;
  &lt;/hibernate-configuration&gt;
  </code></pre>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;?xml version="1.0"?&gt;
  &lt;!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
  "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"&gt;
  &lt;!-- Generated 14-dic-2015 21:00:04 by Hibernate Tools 3.4.0.CR1 --&gt;
  &lt;hibernate-mapping&gt;
      &lt;class name="ch.makery.model.Employee" table="EMPLOYEE"&gt;
          &lt;id name="id" type="int"&gt;
              &lt;column name="ID" /&gt;
              &lt;generator class="assigned" /&gt;
          &lt;/id&gt;
          &lt;property name="firstName" type="java.lang.String"&gt;
              &lt;column name="FIRSTNAME" /&gt;
          &lt;/property&gt;
          &lt;property name="lastName" type="java.lang.String"&gt;
              &lt;column name="LASTNAME" /&gt;
          &lt;/property&gt;
      &lt;/class&gt;
  &lt;/hibernate-mapping&gt;
  </code></pre>
  
  <pre class="lang-java prettyprint-override"><code>package ch.makery.model;
  
  public class Employee {  
      private int id;  
      private String firstName,lastName;  
  
      public int getId() {  
          return id;  
      }  
      public void setId(int id) {  
          this.id = id;  
      }
  
      public String getFirstName() {  
          return firstName;  
      }  
      public void setFirstName(String firstName) {  
          this.firstName = firstName;  
      }   
  
      public String getLastName() {  
          return lastName;  
      }  
      public void setLastName(String lastName) {  
          this.lastName = lastName;  
      }   
  
  }
  </code></pre>
  
  <p>Im not using Spring since Im just creating a desktop application.</p>