title: identifier of an instance was altered from 1 to 2
body: <p>What I am trying to do is read a text file in the code and insert it into a table called employee1. And I am getting this error: </p>
  
  <blockquote>
    <p>Hibernate: insert into EMPLOYEE1 (NAME, SALARY, MANAGER, ID) values
    (?, ?, ?, ?) identifier of an instance of com.Employee altered from 1
    to 2 Exception in thread "main" org.hibernate.HibernateException:
    identifier of an instance of com.Employee altered from 1 to 2     at
    org.hibernate.event.def.DefaultFlushEntityEventListener.checkId(DefaultFlushEntityEventListener.java:51)
      at
    org.hibernate.event.def.DefaultFlushEntityEventListener.onFlushEntity(DefaultFlushEntityEventListener.java:82)
      at
    org.hibernate.event.def.AbstractFlushingEventListener.flushEntities(AbstractFlushingEventListener.java:190)
      at
    org.hibernate.event.def.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:70)
      at
    org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:26)
      at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:669)   at
    roseindia.tutorial.hibernate.FirstExample.main(FirstExample.java:98)</p>
  </blockquote>
  
  <p>Code of the Employee.java</p>
  
  <pre><code>public class Employee 
  {
  
      private int id;
      private String name;
      private double salary;
      private String manager;
  
  
      public int getId() 
      {
          return id;
      }
  
      public void setId(int s) 
      {
          id = s;
      }
      //***************************************************//  
      public String getName() 
      {
          return name;
      }
  
      public void setName(String s) 
      {
          name = s;
      }
      //***************************************************//  
      public double getSalary() 
      {
          return salary;
      }
  
      public void setSalary(double s) 
      {
          salary = s;
      }
      //***************************************************//
      public String getManager() 
      {
          return manager;
      }
  
      public void setManager(String s) 
      {
          manager = s;
      }
  }
  </code></pre>
  
  <p>Code of the EmployeeEx.java(exection)</p>
  
  <pre><code>import java.io.File;
  import java.util.Scanner;
  
  import org.hibernate.Session;
  import org.hibernate.SessionFactory;
  import org.hibernate.Transaction;
  import org.hibernate.cfg.Configuration;
  
  import com.Employee;
  
  public class EmployeeEx 
  {
  
  public static void main(String[] args) 
  {
      Session session = null;
  
      try
      {       
          Transaction transaction = null; 
  
          SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
          session =sessionFactory.openSession();
  
          Employee em = new Employee();   
  
          File f=new File("c:/Class/Employee1.txt") ;
          Scanner scan=new Scanner(f);
          transaction = session.beginTransaction();
          while(scan.hasNext())
          {               
  
              String line=scan.nextLine();            
              String empArray[]=line.split(" ");
  
  
              em.setId(Integer.parseInt(empArray[0]));
              em.setName(empArray[1]);
              em.setSalary(Double.parseDouble(empArray[2]));
              em.setManager(empArray[3]);
  
              session.save(em);
              transaction.commit();
          }
  
  
  }
  catch(Exception e)
  {
      System.out.println(e.getMessage());
  }
  finally
  {
      session.flush();
      session.close();
  
  }
  
  
  }
  
  }
  </code></pre>
  
  <p>The config file:</p>
  
  <pre><code>&lt;?xml version='1.0' encoding='utf-8'?&gt;
  &lt;!DOCTYPE hibernate-configuration PUBLIC
  "-//Hibernate/Hibernate Configuration DTD//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;oracle.jdbc.OracleDriver&lt;/property&gt;
    &lt;property name="hibernate.connection.url"&gt;jdbc:oracle:thin:@localhost:1521:XE&lt;/property&gt;
    &lt;property name="hibernate.connection.username"&gt;system&lt;/property&gt;
    &lt;property name="hibernate.connection.password"&gt;system&lt;/property&gt;
    &lt;property name="hibernate.connection.pool_size"&gt;10&lt;/property&gt;
    &lt;property name="show_sql"&gt;true&lt;/property&gt;
    &lt;property name="dialect"&gt;org.hibernate.dialect.OracleDialect&lt;/property&gt;
    &lt;property name="hibernate.hbm2ddl.auto"&gt;update&lt;/property&gt;
    &lt;!-- Mapping files --&gt;
    &lt;mapping resource="contact.hbm.xml"/&gt;
    &lt;mapping resource="com.hbm.xml"/&gt;
  &lt;/session-factory&gt;
  &lt;/hibernate-configuration&gt;
  </code></pre>
  
  <p>The mapping file:</p>
  
  <pre><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;hibernate-mapping&gt;
  &lt;class name="com.Employee" table="EMPLOYEE1"&gt;
     &lt;id name="id" type="int" column="ID" &gt;
     &lt;generator class="assigned"/&gt;
    &lt;/id&gt;
  
    &lt;property name="name"&gt;
       &lt;column name="NAME" /&gt;
    &lt;/property&gt;
    &lt;property name="salary"&gt;
      &lt;column name="SALARY"/&gt;
    &lt;/property&gt;
    &lt;property name="manager"&gt;
      &lt;column name="MANAGER"/&gt;
    &lt;/property&gt;
  &lt;/class&gt;
  
  &lt;/hibernate-mapping&gt;
  </code></pre>