title: Spring Data JPA inserting instead of Update
body: <p>Hi I am new to <strong>Spring Data JPA</strong> and I am wondering even though I pass the Id to the entity, the Spring data jpa is inserting instead of merge. I thought when I implement the <strong>Persistable</strong> interface and implement the two methods:</p>
  <pre><code>public Long getId();
  public Boolean isNew();
  </code></pre>
  <p>It will automatically merge instead of persist.</p>
  <p>I have an entity class called User like:</p>
  <pre><code>@Entity
  @Table(name = &quot;T_USER&quot;)
  public class User implements Serializable, Persistable&lt;Long&gt; {
  
     @Id
     @GeneratedValue(strategy = GenerationType.AUTO)
     @Column(name = &quot;USER_ID&quot;)
     private Long id;
  
     @Column(name = &quot;CREATION_TIME&quot;, nullable = false)
     private Date creationTime;
  
     @Column(name = &quot;FIRST_NAME&quot;, nullable = false)
     private String firstName;
  
     @Column(name = &quot;LAST_NAME&quot;, nullable = false)
     private String lastName;
  
     @Column(name = &quot;MODIFICATION_TIME&quot;, nullable = false)
     private Date modificationTime;
  </code></pre>
  <p>And have another class</p>
  <pre><code>@Entity
  @Table(name = &quot;T_USER_ROLE&quot;)
  public class UserRole implements Serializable, Persistable&lt;Long&gt; {
  
     @Id
     @GeneratedValue(strategy = GenerationType.AUTO)
     private Long roleId;
  
     @Column(name = &quot;ROLE_NAME&quot;)
     private String userRole;
  }
  </code></pre>
  <p>I have a custom repository called UserRepostory extending JpaReopistory. I am hitting the save for merge and persist as I see the implementation demonstrate that Spring Data Jpa uses above two methods to either update or insert.</p>
  <pre><code>@Repository
  public interface UserRepository extends JpaRepository&lt;User, Long&gt; {
  }
  </code></pre>
  <p>I have been trying to figure out but didn't get any clue. Maybe you
  guys can help.</p>