title: Error when trying to save entities with mapping in Spring-JPA
body: <p>I have the following entity relationship:</p>
  
  <pre><code>@Entity
  @Table(name="order_info")
  public class OrderInfo{
      @OneToMany(mappedBy="orderInfo",fetch=FetchType.EAGER,cascade=CascadeType.ALL)
      @JsonIgnore
      private List&lt;OrderItem&gt; orderItems;
  }
  
  
  @Entity
  @Table(name="reason_codes")
  public class ReasonCode{
      //bi-directional many-to-one association to OrderItem
      @JsonIgnore
      @OneToMany(mappedBy="reasonCode",fetch=FetchType.EAGER,cascade=CascadeType.ALL)
      private List&lt;OrderItem&gt; orderItems;
  }
  
  
  @Entity
  @Table(name="order_item")
  public class OrderItem{
      //bi-directional many-to-one association to OrderInfo
      @ManyToOne
      @JoinColumn(name="order_info_id", nullable=false)
      private OrderInfo orderInfo;
  
      //bi-directional many-to-one association to ReasonCode
      @ManyToOne
      @JoinColumn(name="reason_code_id", nullable=false)
      private ReasonCode reasonCode;
  }
  </code></pre>
  
  <p>Each OrderInfo has many OrderItem, each ReasonCode can be mapped to multiple OrderItems, and each OrderItem MUST have 1 OrderInfo, and 1 ReasonCode.</p>
  
  <p>And finally, the code to set everything up:</p>
  
  <pre><code>class Test{
  
      ...
      List&lt;OrderItem&gt; orderItems = new ArrayList&lt;OrderItem&gt;();
  
      for(...){
          OrderItem item = new OrderItem();
          ReasonCode rrCode = rcRepostory.findOne("2");
          item.setReasonCode(rrCode);
          orderItems.add(item);
      }
  
      OrderInfo order = CreateOrder.create(orderItems);
      orderInfoRepo.save(order);
  }
  
  class CreateOrder{
      public static OrderInfo create(List&lt;OrderItem&gt; orderItems){
        OrderInfo oInfo = new OrderInfo();
        oInfo. setABC(...);
  
        for(OrderItem item : orderItems){
            item.setOrderInfo(oInfo);
        }
  
        oInfo.setOrderItems(orderItems);
        return oInfo;
  
      }
  }
  </code></pre>
  
  <p>Now, when I try to save the orderInfo entity, I get the following error:</p>
  
  <pre><code>Not-null property references a transient value - transient instance must be saved before current operation : model.OrderItem.reasonCode -&gt; model.ReasonCode
  </code></pre>
  
  <p>Basically, what I wan to do is, when I save OrderInfo, I want the OrderItems to be saved as well.</p>
  
  <p>From the many posts that I saw online, adding the fetch as eager, and cascade on the many-to-one mapping should resolve this. However, I still face the issue even after adding them.</p>
  
  <p>The ReasonCode already exists in the database. What is the problem here?</p>
  
  <p>Thanks.</p>