title: Hibernate Session Saving same object twice
body: <p>Hello Every time I try to save an object in Hibernate , it is saving twice can anyone  help me.</p>
  
  <p>Note: The below log messages are displayed after  <code>session.saveOrUpdate(register);</code> line </p>
  
  <p><strong>My Code is</strong> </p>
  
  <pre><code>Session session = null;
          Transaction transaction = null;
          try {
              session = this.sessionFactory.getCurrentSession();
              transaction = session.beginTransaction();
              session.saveOrUpdate(register);
              transaction.commit();
              session.close();
              return true;
          } catch (HibernateException ex) {
              transaction.rollback();
          }
  </code></pre>
  
  <p><strong>My log is</strong> </p>
  
  <p>Hibernate: <code>insert into UserRegister (address1, address2, bloodGroup, addressCity, dateOfBirth, firstName, gender, lastName, password, phoneNumber, addressState, userEmail, userName, addresszipCode) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)</code></p>
  
  <p>Hibernate: <code>insert into UserRegister (address1, address2, bloodGroup, addressCity, dateOfBirth, firstName, gender, lastName, password, phoneNumber, addressState, userEmail, userName, addresszipCode) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)</code></p>
  
  <p>My entity is </p>
  
  <pre><code>@Entity
  @Table(name = "UserRegister", uniqueConstraints = {
  @UniqueConstraint(columnNames = {"id"})})
  public class User implements Serializable {
  
      private static final long serialVersionUID = -77886191777123344L;
  
      @Id
      @GeneratedValue(strategy = GenerationType.IDENTITY)
      @Column(name = "id", nullable = false, unique = true, length = 11)
      private int userID;
  
      @Column(name = "firstName", nullable = false)
      private String firstName;
  
      @Column(name = "lastName", nullable = false)
      private String lastName;
  
      @Column(name = "userName", nullable = false)
      private String userName;
  
      @Column(name = "password", nullable = false)
      private String password;
  
      @Column(name = "gender", nullable = false)
      private String gender;
  
      @Column(name = "dateOfBirth", nullable = false)
      private Timestamp dateOfBirth;
  
      @Column(name = "bloodGroup", nullable = true)
      private String bloodGroup;
  
      @Column(name = "userEmail", nullable = false)
      private String userEmail;
  
      @Column(name = "phoneNumber", nullable = false)
      private String phoneNumber;
  
      @Column(name = "address1", nullable = false)
      private String address1;
  
      @Column(name = "address2")
      private String address2;
  
      @Column(name = "addressCity")
      private String city;
  
      @Column(name = "addressState")
      private String state;
  
      @Column(name = "addresszipCode")
      private String zipCode;
  
      @OneToMany(cascade = CascadeType.ALL)
      @JoinColumn(name="userID")
      private List&lt;UserMessages&gt; userMessages;
  </code></pre>
  
  <p>My UserMessages Entity is </p>
  
  <pre><code>@Entity
  @Table(name = "UserMessages", uniqueConstraints = {
      @UniqueConstraint(columnNames = {"id"})})
  public class UserMessages implements Serializable {
      private static final long serialVersionUID = -77886191777123344L;
      @Id
      @GeneratedValue(strategy = GenerationType.IDENTITY)
      @Column(name = "id", nullable = false, unique = true, length = 11)
      private int messageID;
  
      @Column(name = "fromName", nullable = false)
      private String fromName;
  
      @Column(name = "message", nullable = false)
      private String message;
  
      @Column(name = "messageTime", nullable = false)
      private Timestamp messageTime;
  
      @Column(name = "fromPhoneNumber", nullable = false)
      private String fromPhoneNumber;
  
      @ManyToOne
      @JoinColumn(name="userID", insertable=false, updatable=false)
      private User user;
  </code></pre>