title: Primary key with two field
body: <p>I search a way to create a primary key with two values.</p>
  
  <p>I need to get the current year add it to a sequence (this sequence need to be restarted at the beginning of every year.</p>
  
  <p><strong>For 2018</strong> </p>
  
  <pre><code>First record: 20181
  Second record: 20182
  </code></pre>
  
  <p><strong>For 2019</strong> </p>
  
  <pre><code>First record: 20191
  </code></pre>
  
  <p>I was thinking to use <code>embededid</code> who include a sequence that I would reset every year.</p>
  
  <p>Edit</p>
  
  <pre><code>@Entity
  @Inheritance(strategy = InheritanceType.SINGLE_TABLE)
  public class Cars {
  
      @EmbeddedId
      private EmbedddedCarsKey id;
  
  }
  
  @Embeddable
  public class EmbedddedCarsKey implements Serializable {
  
      private int year;
  
      @SequenceGenerator(name = "cars_id_seq", sequenceName = "cars_id_seq", allocationSize = 1)
      @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "cars_id_seq")
      private Integer seq
  
      public EmbedddedCarsKey();
        year = LocalDate.now().getYear();
      }
  
  }
  </code></pre>
  
  <p>When I try to save I get </p>
  
  <pre><code>Cars cars = new Cars();
  cars.setName("Honda");
  
  carsRepository.save(cars);
  </code></pre>
  
  <blockquote>
    <p>org.hibernate.id.IdentifierGenerationException: null id generated
    for:class com.ush.mcl.model.Cars</p>
  </blockquote>
  
  <p>Edit 2</p>
  
  <p>tried that...</p>
  
  <pre><code>cars = new Cars
  EmbedddedCarsKey key= new EmbedddedCarsKey();
  cars.setId(key);
  </code></pre>
  
  <p>but seq value stay null;</p>