title: Spring JPA saving distinct entities with composite primary key not working as expected, updates same entity
body: <p>I have a logic that saves some data and I use spring boot + spring data jpa.</p>
  
  <p>Now, I have to save one object, and after moment, I have to save another objeect.
  those of object consists of three primary key properties.
  - <strong>partCode, setCode, itemCode</strong>.</p>
  
  <p>let's say first object has a toString() returning below:</p>
  
  <p><strong>SetItem(partCode=10-001, setCode=04, itemCode=01-0021, qty=1.0, sortNo=2, item=null)</strong></p>
  
  <p>and the second object has a toString returning below:</p>
  
  <p><strong>SetItem(partCode=10-001, setCode=04, itemCode=01-0031, qty=1.0, sortNo=2, item=null)</strong></p>
  
  <p>there is a difference on itemCode value, and itemCode property is belonged to primary key, so the two objects are different each other.</p>
  
  <p>but in my case, when I run the program, the webapp saves first object, and updates first object with second object value, not saving objects seperately.</p>
  
  <p><a href="https://i.stack.imgur.com/irtYb.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/irtYb.png" alt="enter image description here"></a></p>
  
  <p>(above image contains different values from this post question)</p>
  
  <p>Here is my entity information:</p>
  
  <pre><code>/**
   * The persistent class for the set_item database table.
   *
   */
  @Data
  @DynamicInsert
  @DynamicUpdate
  @Entity
  @ToString(includeFieldNames=true)
  @Table(name="set_item")
  @IdClass(SetGroupId.class)
  public class SetItem  extends BasicJpaModel&lt;SetItemId&gt; {
      private static final long serialVersionUID = 1L;
  
      @Id
      @Column(name="PART_CODE")
      private String partCode;
  
      @Id
      @Column(name="SET_CODE")
      private String setCode;
  
      @Id
      @Column(name="ITEM_CODE")
      private String itemCode;
  
      private Double qty;
  
      @Column(name="SORT_NO")
      private int sortNo;
  
      @Override
      public SetItemId getId() {
  
          if(BooleanUtils.ifNull(partCode, setCode, itemCode)){
              return null;
          }
          return SetItemId.of(partCode, setCode, itemCode);
      }
  
      @ManyToMany(fetch=FetchType.LAZY)
      @JoinColumns(value = {
              @JoinColumn(name="PART_CODE", referencedColumnName="PART_CODE", insertable=false, updatable=false)
              , @JoinColumn(name="ITEM_CODE", referencedColumnName="ITEM_CODE", insertable=false, updatable=false)
      })
      private List&lt;Item&gt; item;
  
  }
  </code></pre>
  
  <p><strong>So the question is,
  how do I save objects separately which the objects' composite primary keys are partially same amongst them.</strong></p>
  
  <p><strong>EDIT:</strong>
  The entity extends below class:</p>
  
  <pre><code>@Setter
  @Getter
  @MappedSuperclass
  @DynamicInsert
  @DynamicUpdate
  public abstract class BasicJpaModel&lt;PK extends Serializable&gt; implements Persistable&lt;PK&gt;, Serializable {
  
      @Override
      @JsonIgnore
      public boolean isNew() {
          return null == getId();
      }
  }
  </code></pre>
  
  <p><strong>EDIT again</strong>: embeddable class. 
  after soneone points out embeddable class, I noticed there are only just two properties, it should be three of it. thank you.</p>
  
  <pre><code>@Data
  @NoArgsConstructor
  @RequiredArgsConstructor(staticName="of")
  @Embeddable
  public class SetGroupId implements Serializable {
      //default serial version id, required for serializable classes.
      private static final long serialVersionUID = 1L;
  
      @NonNull
      private String partCode;
  
      @NonNull
      private String setCode;
  
  }
  </code></pre>