title: How do I use auto generated id in code with Spring Data?
body: <p>When entity is created it usually receives some auto generated int value for primary key. And I have entity called 'Attribute', that can have a list of related 'Parameter' entities.</p>
  
  <pre><code>@Entity
  @Table(name = "ATTRIBUTES")
  public class Attribute {
      @Id
      @GeneratedValue(strategy = GenerationType.SEQUENCE)
      @Column(name = "ATTRIBUTE_ID", length = 10, nullable = false)
      private int id;
  
      @Column(name = "NAME")
      private String name;
  
      @JsonIgnore
      @LazyCollection(LazyCollectionOption.FALSE)
      @OneToMany(mappedBy = "attribute", cascade = CascadeType.ALL)
      private List&lt;Parameter&gt; parameters;
  </code></pre>
  
  <p>And next I have entity called 'Parameter' that needs to be linked with 'Attribute'. So when I create a 'Parameter' I need to specify its 'Attribute'.
  How do I do that? What's the trick?</p>
  
  <pre><code>@Entity
  @Table(name = "PARAMS")
  public class Parameter {
      @Id
      @GeneratedValue(strategy = GenerationType.SEQUENCE)
      @Column(name = "PARAMETER_ID", length = 10, nullable = false)
      private int id;
  
      @JsonIgnore
      @ManyToOne
      @JoinColumn(name = "ATTRIBUTE_ID", referencedColumnName = "ATTRIBUTE_ID")
      private Attribute attribute;
  
      @Column(name = "VALUE")
      private String value;
  </code></pre>