title: Hibernate: insert data with foreign key
body: <p>I have the following two tables in my database:</p>
  
  <p>Calendar(id, name, user_id)</p>
  
  <p>User(id, name, ...)</p>
  
  <p>Each calendar is owned by one user, each user can have multiple calendars. Hence, there is a many-to-one relationship from Calendar to User. Now I'd like to insert a set of data into my Calendar table, my Calendar Entity looks like this:</p>
  
  <pre><code>@Entity
  @Table(name = "calendar")
  public class Calendar {
  
      @Id 
      @GeneratedValue(generator = "uuid2")
      @GenericGenerator(name = "uuid2", strategy = "uuid2")
      @Column(name = "id", columnDefinition = "BINARY(16)")
      private UUID id;
  
      @Column(name = "name")
      private String name;
  
      @ManyToOne
      @JoinColumn(name = "owner", referencedColumnName = "id")
      private User owner;
      ...
  }
  </code></pre>
  
  <p>However, when I am inserting the data set, I do know the owner's id, but I don't have the corresponding <code>User</code> object. Do I have to retrieve the <code>User</code> object, set <code>owner</code> to it and then insert the data set?</p>
  
  <p>This sounds a little inconvenient to me, is there a way to insert the data set using the <code>User</code> id as it would be stored in the database, as opposed to using a <code>User</code> object?</p>