title: How to send only the ID the of main nested objects in the body request in spring boot
body: <p>I'm creating eCommerce for merchants using spring boot with JPA.
  I have an issue while creating the order service.
  I want to only pass the ID of the nested objects in the request body instead of sending the full nest objects because the size will be extremely big.</p>
  <p>Here is my code.
  <strong>Merchant can do many orders</strong></p>
  <p><strong>Order</strong></p>
  <pre><code>@Entity
  @Table(name = &quot;Orders&quot;)
  @XmlRootElement
  @JsonIgnoreProperties({&quot;hibernateLazyInitializer&quot;, &quot;handler&quot;})
  public class Order extends BasicModelWithIDInt {
  
      @Basic(optional = false)
      @Column(name = &quot;Quantity&quot;)
      private Integer quantity;
  
      @Basic(optional = false)
      @Size(min = 1, max = 150)
  
      @Column(name = &quot;Notes&quot;)
      private String notes;
  
  
      @JoinColumn(name = &quot;ProductID&quot;, referencedColumnName = &quot;ID&quot;)
      @ManyToOne(optional = false, fetch = FetchType.LAZY)
      @JsonIgnoreProperties
      private Product productID;
  
      @JoinColumn(name = &quot;MerchantID&quot;, referencedColumnName = &quot;ID&quot;)
      @ManyToOne(optional = false, fetch = FetchType.LAZY)
      private Merchent merchent;
  
      @JoinColumn(name = &quot;OrderSatusID&quot;, referencedColumnName = &quot;ID&quot;)
      @ManyToOne(optional = false, fetch = FetchType.EAGER)
      private OrderStatus orderStatus;
  
  
        // Getters and Setters
  }
  </code></pre>
  <p><strong>Order Holder</strong></p>
  <pre><code>public class OrderHolder {
  
      @NotNull
      private Order order;
  
      public Order getOrder() {
          return order;
      }
  
      public void setOrder(Order order) {
          this.order = order;
      }
  }
  </code></pre>
  <p><strong>OrderRepo</strong></p>
  <pre><code>public interface OrderRepo extends JpaRepository&lt;Order, Integer&gt; {
  }
  </code></pre>
  <p><strong>Order Controller</strong></p>
  <pre><code>@RestController
  @RequestMapping(value = &quot;order&quot;, produces = MediaType.APPLICATION_JSON_VALUE)
  public class OrderRestController extends BasicController&lt;OrderHolder&gt;{
  
      @Autowired
      private OrderRepo orderRepo;
  
  
   
  
  
      @PostMapping(&quot;create&quot;)
      public ResponseEntity&lt;?&gt; create(@RequestBody @Valid OrderHolder orderHolder, Principal principal) throws GeneralException {
          log.debug( &quot;create order {} requested&quot;, orderHolder.toString());
          Order order = new Order();
          order = orderHolder.getOrder();
          System.out.println(&quot;###############&quot;+order);
          try {
              order = orderRepo.save(order);
              log.info( &quot;Order {} has been created&quot;, order );
          } catch (Exception e) {
              log.error( &quot;Error creating Order:  &quot;, e );
              e.printStackTrace();
              throw new GeneralException( Errors.ORDER_CREATION_FAILURE, e.toString() );
          }
          return ResponseEntity.ok( order );
      }
  
  }
  </code></pre>
  <p>I need request body to look like the below instead of including the full Merchant and Product objects inside the request.</p>
  <p><a href="https://i.stack.imgur.com/9zmM7.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/9zmM7.png" alt="enter image description here" /></a></p>