title: The update method in hibernate does not replace the old data but create a new one?
body: <p>Here are my simple code, save some code in XML file.</p>
  
  <pre><code>&lt;?xml version='1.0' encoding='utf-8'?&gt;
  
      &lt;!-- JDBC connection pool (use the built-in) --&gt;
      &lt;property name="connection.pool_size"&gt;1&lt;/property&gt;
  
      &lt;!-- SQL dialect --&gt;
      &lt;property name="dialect"&gt;org.hibernate.dialect.MySQLDialect&lt;/property&gt;
  
      &lt;!-- Disable the second-level cache  --&gt;
      &lt;property name="cache.provider_class"&gt;org.hibernate.cache.NoCacheProvider&lt;/property&gt;
  
      &lt;!-- Echo all executed SQL to stdout --&gt;
      &lt;property name="show_sql"&gt;true&lt;/property&gt;
  
      &lt;!-- Drop the existing tables and create new one --&gt;
      &lt;property name="hbm2ddl.auto"&gt;update&lt;/property&gt;
  
      &lt;!-- Mention here all the model classes along with their package name --&gt;
  
      &lt;mapping class="com.hibernate.Student"/&gt;
  
  &lt;/session-factory&gt;
  </code></pre>
  
  <p></p>
  
  <p>Here is my student class,</p>
  
  <pre><code>package com.hibernate;
  import javax.persistence.Column;
  import javax.persistence.Entity;
  import javax.persistence.GeneratedValue;
  import javax.persistence.GenerationType;
  import javax.persistence.Id;
  import javax.persistence.Table;
  
  
  @Entity
  @Table(name="STUDENT")
  public class Student {
  
  @Id @GeneratedValue(strategy=GenerationType.AUTO)
  private int rollNo;
  
  @Column(name="FULL_NAME",nullable=false)
  private String name;
  
  public int getRollNo() {
      return rollNo;
  }
  public void setRollNo(int rollNo) {
      this.rollNo = rollNo;
  }
  public String getName() {
      return name;
  }
  public void setName(String name) {
      this.name = name;
  }
  }
  </code></pre>
  
  <p>And the main:</p>
  
  <pre><code>package com.hibernate;
  import org.hibernate.Session;
  import org.hibernate.SessionFactory;
  import org.hibernate.cfg.Configuration;
  
  public class Main {
      public static void main(String[] args){
          Student student= new Student();
          student.setName("Chang");
          SessionFactory sessionFactory=new Configuration().configure().buildSessionFactory();
          Session session=sessionFactory.openSession();
          session.beginTransaction();
  
          //session.save(student);
  
          //get a student from the databse
          student=(Student)session.get(Student.class, 1);
          System.out.println("Student Object have student name as:"+student.getName());
  
          student.setName("Chang_update");
          session.update(student);
  
          session.getTransaction().commit();
          session.close();
          //sessionFactory.close();       
      }
  }
  </code></pre>
  
  <p>At first, I want to create a new table and insert a new student. So I let the <code>&lt;property name="hbm2ddl.auto"&gt;create&lt;/property&gt;</code>. And I have a <code>session.save(student);</code> I do not have these part of code:        </p>
  
  <pre><code>student=(Student)session.get(Student.class, 1);
  System.out.println("Student Object have student name as:"+student.getName());
  
  student.setName("Chang_update");
  session.update(student);
  </code></pre>
  
  <p>Then I want to test the get and update method. So I changed the <code>&lt;property name="hbm2ddl.auto"&gt;update&lt;/property&gt;</code> , delete <code>session.save(student);</code> and add  </p>
  
  <pre><code>student=(Student)session.get(Student.class, 1);
  System.out.println("Student Object have student name as:"+student.getName());
  
  student.setName("Chang_update");
  session.update(student);
  </code></pre>
  
  <p>Then I run the code. The get method works good with a return Chang. But for the update method, i thought it will replace the old data. But it came out with a new student called Chang_update with a RollNo of 1. The old Chang's RollNo became 2. </p>
  
  <p>I am new to hibernate, can you guys give me a hint what is going on here?</p>