title: How to write entity and post request for a table with a foreign key (by id)
body: <p>I have a table "product" with two FKs manufactor and category. I want to write a query so, that when you add a product, you don't create a manufacture every time, but select it by id from the available ones.
  <a href="https://i.stack.imgur.com/ZcA7L.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ZcA7L.png" alt="uml diagram for tables"></a> 
  Now I have:
    My Product entity:</p>
  
  <pre><code>    @ManyToOne(fetch = FetchType.EAGER, optional = false)
      @JoinColumn(name="manufactor",  referencedColumnName = "id")
      private Manufactor manufactor;
  
      public void setManufactor(Manufactor manufactor) {
          this.manufactor = manufactor;  }
  
      public Manufactor getManufactor() {
          return manufactor;  }
  </code></pre>
  
  <p>My Controller:</p>
  
  <pre><code>    @RequestMapping(value = "/addProduct", method = RequestMethod.POST)
      public Product addNewProduct (@RequestBody Product product ) {
          return productRepository.save(product);
      }
  </code></pre>
  
  <p><em>My request should look something like this:</em></p>
  
  <pre><code>{   "name": "Alakazai",
      "quantity": 1,
      "price": 58,
      "manufactor": 2,
      "category": 3
  }
  </code></pre>
  
  <p>But when I use postman I have the error:</p>
  
  <pre><code>    "status": 400,
      "error": "Bad Request",
      "message": "Invalid JSON input: Cannot construct instance of `com.store.Entity.Manufactor` (although at least one Creator exists): no int/Int-argument constructor/factory method to deserialize from Number value (1); nested exception is com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot construct instance of `com.store.Entity.Manufactor` (although at least one Creator exists): no int/Int-argument constructor/factory method to deserialize from Number value (1)\n at [Source: (PushbackInputStream); line: 5, column: 16] (through reference chain: com.store.Entity.Product[\"manufactor\"])",
  </code></pre>
  
  <p>What mistake did I make? In product entity or somewhere else? I will glad to any explanation</p>
  
  <p>If you need, my project on github: <a href="https://github.com/Asel06/online_store" rel="nofollow noreferrer">Project</a></p>