title: Hibernate Field annotation joinColumn set id and get object
body: <p>Is there anyway to <strong>set id and get project object</strong> for the below <strong>project</strong> field using <strong>filed annotation</strong>. so that i can set only <strong>project id</strong> while persisting in this child table <strong>instead of setting the whole object</strong> while persisting since we are going to save only id of project in board_project table. My be a duplicate i couldn't find other links. This is like <strong>we are in practice of using filed annotation instead of method</strong>.</p>
  
  <p>Using : hibernate5.0 - jpa2.1 lombok(i.e getter/setter) for Spring-data-commons-1.13 for CRUD Operations</p>
  
  <pre><code>import lombok.AllArgsConstructor;
  import lombok.Getter;
  import lombok.NoArgsConstructor;
  import lombok.Setter;
  
  import javax.persistence.Column;
  import javax.persistence.Entity;
  import javax.persistence.GeneratedValue;
  import javax.persistence.Id;
  import javax.persistence.JoinColumn;
  import javax.persistence.ManyToOne;
  import javax.persistence.SequenceGenerator;
  import javax.persistence.Table;
  
  @Getter
  @Setter
  @NoArgsConstructor
  @AllArgsConstructor
  @Entity
  @Table(name = "board_project")
  public class BoardProject {
  
      @Id
      @SequenceGenerator(name = "board_project_id_generator", sequenceName = "board_project_id_seq", allocationSize = 1)
      @GeneratedValue(generator = "board_project_id_generator")
      private Long id;
  
      @Column(name = "board_id")
      private Long boardId;
  
      @ManyToOne
      @JoinColumn(name = "project_id")
      private Project project;          // field set id and get object
     }
  </code></pre>
  
  <p>Project Entity :</p>
  
  <pre><code>public class Project{
  
      @Id
      @SequenceGenerator(name = "project_id_generator", sequenceName = "project_id_seq", allocationSize = 1)
      @GeneratedValue(generator = "project_id_generator")
      private Long id;
  
      @Column(name = "name")
      private String name;
  }
  </code></pre>
  
  <p>Update: Found something like this </p>
  
  <blockquote>
  <pre><code>@ManyToOne
  @JoinColumn(name = "project_id", updatable = false, insertable = false)
  private Project project;
  
  @Column(name = "project_id")
  @NotNull
  private Long projectId;
  </code></pre>
  </blockquote>
  
  <p>Don't know is it ok</p>
  
  <p>Any help on this would be great.</p>