title: How to fix my first Hibernate JAVA program
body: <p>I created a new Maven project , I installed JBoss tools in Eclipse Kepler (including Hibernate) and I wanted to test a Hibernate program so I did this program below, but when I run as Java program I get errors / exceptions.</p>
  
  <p>Here are my files : </p>
  
  <p><img src="https://i.stack.imgur.com/TdXMc.png" alt="Structure"></p>
  
  <p>File SaveStudent.java : </p>
  
  <pre><code>package com.hibernate.demo;
  
  import com.hibernate.entity.student;
  import org.hibernate.Session;
  import org.hibernate.SessionFactory;
  import org.hibernate.cfg.Configuration;
  
  
  public class SaveStudent {
  
      public static void main(String[] args) {
  
          SessionFactory f = new Configuration()
                          .configure("hibernate.cfg.xml")
                          .addAnnotatedClass(student.class)
                          .buildSessionFactory();
  
          Session session = f.getCurrentSession();
  
          try {
              System.out.println("Creating student...");
              student st = new student("X","X","xx@xx.xx");
  
              session.getTransaction();
  
              System.out.println("Saving ...");
              session.save(st);
  
              session.getTransaction().commit();
  
              System.out.println("Done!!!");
  
          } finally {
              session.close();
              f.close();
          }
  
      }
  
  }
  </code></pre>
  
  <p>File student.java : </p>
  
  <pre><code>package com.hibernate.entity;
  
  import javax.persistence.Column;
  import javax.persistence.Entity;
  import javax.persistence.Id;
  import javax.persistence.Table;
  
  @Entity
  @Table(name="hbstudent")
  public class student {
      @Id
      @Column(name="id")
      private int id;
  
      @Column(name="first")
      private String firstname;
  
      @Column(name="last")
      private String lastname;
  
      @Column(name="email")
      private String email;
  
  public student (){
  }
  
  public student(String firstname, String lastname, String email) {
      this.firstname = firstname;
      this.lastname = lastname;
      this.email = email;
  }
  
  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;
  }
  
  public String getEmail() {
      return email;
  }
  
  public void setEmail(String email) {
      this.email = email;
  }
  
  @Override
  public String toString() {
      return "student [id=" + id + ", firstname=" + firstname + ", lastname="
              + lastname + ", email=" + email + "]";
  }
  
  
  
  }
  </code></pre>
  
  <p>Here is my POM.XML : </p>
  
  <pre><code>    &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/maven-v4_0_0.xsd"&gt;
      &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
    &lt;groupId&gt;hibernate-tuto&lt;/groupId&gt;
    &lt;artifactId&gt;hibernate-tuto&lt;/artifactId&gt;
    &lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt;
  
  
        &lt;dependencies&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.hibernate&lt;/groupId&gt;
          &lt;artifactId&gt;ejb3-persistence&lt;/artifactId&gt;
          &lt;version&gt;3.3.2.Beta1&lt;/version&gt;
          &lt;type&gt;pom&lt;/type&gt;
      &lt;/dependency&gt;
  
          &lt;dependency&gt;
          &lt;groupId&gt;org.slf4j&lt;/groupId&gt;
          &lt;artifactId&gt;slf4j-api&lt;/artifactId&gt;
          &lt;version&gt;1.6.6&lt;/version&gt;
      &lt;/dependency&gt;
  
  
      &lt;dependency&gt;
          &lt;groupId&gt;org.hibernate&lt;/groupId&gt;
          &lt;artifactId&gt;hibernate-annotations&lt;/artifactId&gt;
          &lt;version&gt;3.5.6-Final&lt;/version&gt;
      &lt;/dependency&gt;
  
      &lt;dependency&gt;
          &lt;groupId&gt;org.hibernate&lt;/groupId&gt;
          &lt;artifactId&gt;hibernate-cglib-repack&lt;/artifactId&gt;
          &lt;version&gt;2.1_3&lt;/version&gt;
      &lt;/dependency&gt;
  
      &lt;dependency&gt;
      &lt;groupId&gt;mysql&lt;/groupId&gt;
      &lt;artifactId&gt;mysql-connector-java&lt;/artifactId&gt;
      &lt;version&gt;5.1.6&lt;/version&gt;
      &lt;/dependency&gt;
                   &lt;dependency&gt;
          &lt;groupId&gt;org.slf4j&lt;/groupId&gt;
          &lt;artifactId&gt;slf4j-api&lt;/artifactId&gt;
          &lt;version&gt;1.6.6&lt;/version&gt;
      &lt;/dependency&gt;
  
      &lt;dependency&gt;
          &lt;groupId&gt;org.slf4j&lt;/groupId&gt;
          &lt;artifactId&gt;slf4j-log4j12&lt;/artifactId&gt;
          &lt;version&gt;1.6.6&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;log4j&lt;/groupId&gt;
          &lt;artifactId&gt;log4j&lt;/artifactId&gt;
          &lt;version&gt;1.2.16&lt;/version&gt;
      &lt;/dependency&gt;
  
  &lt;dependency&gt;
      &lt;groupId&gt;org.ow2.asm&lt;/groupId&gt;
      &lt;artifactId&gt;asm&lt;/artifactId&gt;
      &lt;version&gt;4.0&lt;/version&gt;
  &lt;/dependency&gt;
              &lt;dependency&gt;
      &lt;groupId&gt;cglib&lt;/groupId&gt;
      &lt;artifactId&gt;cglib&lt;/artifactId&gt;
      &lt;version&gt;3.1&lt;/version&gt;
  &lt;/dependency&gt;
              &lt;dependency&gt;
      &lt;groupId&gt;commons-logging&lt;/groupId&gt;
      &lt;artifactId&gt;commons-logging&lt;/artifactId&gt;
      &lt;version&gt;1.1.3&lt;/version&gt;
  &lt;/dependency&gt;
  &lt;dependency&gt;
      &lt;groupId&gt;mysql&lt;/groupId&gt;
      &lt;artifactId&gt;mysql-connector-java&lt;/artifactId&gt;
      &lt;version&gt;5.1.6&lt;/version&gt;
  &lt;/dependency&gt;
  
              &lt;dependency&gt;
      &lt;groupId&gt;org.hibernate&lt;/groupId&gt;
      &lt;artifactId&gt;ejb3-persistence&lt;/artifactId&gt;
      &lt;version&gt;3.3.2.Beta1&lt;/version&gt;
  &lt;/dependency&gt;
  
      &lt;dependency&gt;
          &lt;groupId&gt;org.hibernate&lt;/groupId&gt;
          &lt;artifactId&gt;hibernate&lt;/artifactId&gt;
          &lt;version&gt;3.6.0.Beta2&lt;/version&gt;
          &lt;type&gt;pom&lt;/type&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
      &lt;groupId&gt;commons-io&lt;/groupId&gt;
      &lt;artifactId&gt;commons-io&lt;/artifactId&gt;
      &lt;version&gt;2.3&lt;/version&gt;
  &lt;/dependency&gt;
  
              &lt;dependency&gt;
      &lt;groupId&gt;org.hibernate&lt;/groupId&gt;
      &lt;artifactId&gt;ejb3-persistence&lt;/artifactId&gt;
      &lt;version&gt;3.3.2.Beta1&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.6.Final&lt;/version&gt;
  &lt;/dependency&gt;
  
  &lt;dependency&gt;
      &lt;groupId&gt;org.hibernate.common&lt;/groupId&gt;
      &lt;artifactId&gt;hibernate-commons-annotations&lt;/artifactId&gt;
      &lt;version&gt;5.0.1.Final&lt;/version&gt;
  &lt;/dependency&gt;
  
  
  
  &lt;dependency&gt;
      &lt;groupId&gt;org.hibernate.javax.persistence&lt;/groupId&gt;
      &lt;artifactId&gt;hibernate-jpa-2.1-api&lt;/artifactId&gt;
      &lt;version&gt;1.0.0.Final&lt;/version&gt;
  &lt;/dependency&gt;
  
  
  
      &lt;dependency&gt;
          &lt;groupId&gt;org.hibernate&lt;/groupId&gt;
          &lt;artifactId&gt;hibernate&lt;/artifactId&gt;
          &lt;version&gt;3.6.0.Beta2&lt;/version&gt;
          &lt;type&gt;pom&lt;/type&gt;
      &lt;/dependency&gt;
  
      &lt;/dependencies&gt;
  &lt;/project&gt;
  </code></pre>
  
  <p>Hibernate Configuration file : </p>
  
  <pre><code>&lt;!DOCTYPE hibernate-configuration PUBLIC
          "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
          "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd"&gt;
  
  &lt;hibernate-configuration&gt;
  
      &lt;session-factory&gt;
  
          &lt;!-- JDBC Database connection settings --&gt;
          &lt;property name="connection.driver_class"&gt;com.mysql.jdbc.Driver&lt;/property&gt;
          &lt;property name="connection.url"&gt;jdbc:mysql://localhost:3306/student?useSSL=false&lt;/property&gt;
          &lt;property name="connection.username"&gt;root&lt;/property&gt;
          &lt;property name="connection.password"&gt;&lt;/property&gt;
  
          &lt;!-- JDBC connection pool settings ... using built-in test pool --&gt;
          &lt;property name="connection.pool_size"&gt;1&lt;/property&gt;
  
          &lt;!-- Select our SQL dialect --&gt;
          &lt;property name="dialect"&gt;org.hibernate.dialect.MySQLDialect&lt;/property&gt;
  
          &lt;!-- Echo the SQL to stdout --&gt;
          &lt;property name="show_sql"&gt;true&lt;/property&gt;
  
          &lt;!-- Set the current session context --&gt;
          &lt;property name="current_session_context_class"&gt;thread&lt;/property&gt;
  
      &lt;/session-factory&gt;
  
  &lt;/hibernate-configuration&gt;
  </code></pre>
  
  <p>The error I get : </p>
  
  <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.
  Exception in thread "main" java.lang.NoSuchMethodError: org.hibernate.cfg.annotations.reflection.JPAMetadataProvider.&lt;init&gt;(Lorg/hibernate/boot/spi/MetadataBuildingOptions;)V
      at org.hibernate.boot.internal.MetadataBuilderImpl$MetadataBuildingOptionsImpl.generateDefaultReflectionManager(MetadataBuilderImpl.java:742)
      at org.hibernate.boot.internal.MetadataBuilderImpl$MetadataBuildingOptionsImpl.&lt;init&gt;(MetadataBuilderImpl.java:715)
      at org.hibernate.boot.internal.MetadataBuilderImpl.&lt;init&gt;(MetadataBuilderImpl.java:127)
      at org.hibernate.boot.MetadataSources.getMetadataBuilder(MetadataSources.java:135)
      at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:654)
      at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:726)
      at com.hibernate.demo.SaveStudent.main(SaveStudent.java:16)
  </code></pre>