title: JPA foreign key NOT AS OBJECT
body: <p>I have two simple tables in MySQL</p>
  
  <pre><code>User ---(one-to-many)--- Expense
  </code></pre>
  
  <p>I am using Spring JPA to generate theses two entities. Expense has 'user_id' foreign key field which references 'id' field in User table.</p>
  
  <p>I use JSON in requests to populate tables</p>
  
  <pre><code>User
  {"id":1, "username":"user"}
  
  Expense
  {
   "id":1, 
   "user_id":1,        &lt;--- this value is not null in MySQL
   "expense":"expense"
  }
  </code></pre>
  
  <p>When calling API I already have <strong>user_id</strong> value and I don't want to pass the whole object.</p>
  
  <p>Is there a way to tell Spring that this is INTEGER FOREIGN KEY that references 'id' column in 'User' table? </p>
  
  <p>All the examples I found online only showed how to achieve by passing whole 'User' object in the JSON.</p>
  
  <p>My current implementation:</p>
  
  <pre><code>@Entity
  public class User{
      @Id
      @GeneratedValue(strategy = GenerationType.IDENTITY)
      @Column(name = "id", updatable = false, nullable = false)
      private int id;
  
      private String username; 
  }
  
  @Entity
  public class Car{
      @Id
      @GeneratedValue(strategy = GenerationType.IDENTITY)
      @Column(name = "id", updatable = false, nullable = false)
      private int id;
  
      @ManyToOne
      private User user_id;
  
      private String expense;
  }
  </code></pre>