| I use spring boot 2 with jpa and hibernate For a PK, I try to use currear year (create of the record) + id seq (reinit every 1 day of the year)
@Entity
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
public class Samplings {
@EmbeddedId
private EmbedddedSamplesKey id;
}
@Embeddable
public class EmbedddedSamplesKey extends AbstractId implements Serializable {
@Column(name="year")
private int year;
@PrePersist
public void prePersist() {
year = LocalDate.now().getYear();
}
}
@MappedSuperclass
public abstract class AbstractId {
@Id
@SequenceGenerator(name = "samplings_id_seq", sequenceName = "samplings_id_seq", allocationSize = 1)
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "samplings_id_seq")
private Integer seq;
}
I create an abstract class because i read on the web... @Id can't be used in Embeddable... I get this error org.hibernate.MappingException: component property not found: seq Same thing if i take code of AbstractId and put it directly in EmbedddedSamplesKey |