I'm usign @GeneratedValue(strategy = GenerationType.AUTO) to generate the ID on my entity.
I don't now how it works, but on my child table, generates ID values, that follow the parent sequence.
//parent table
@Entity
@Table (name = "parent")
public class Parent {
@Id
@GeneratedValue (strategy = GenerationType.AUTO)
@Column (name = "id")
private long id;
@OneToMany (cascade = {CascadeType.ALL}, fetch = FetchType.LAZY)
@JoinColumn (name = "parentId")
@ForeignKey (name = "FKparent")
private List<child> child;
}
//child table
@Entity
@Table (name = "child")
public class Child {
@Id
@GeneratedValue (strategy = GenerationType.AUTO)
@Column (name = "id")
private long id;
}
The inserted ID values on parent, updates the sequence. The inserted ID values on child, updates the sequence. On the next insert of parent, the sequence... uses values updated by child insertions...
This Annotations, aren't creating two sequences, only one. Is this correct/expected?
I inserted my entities with my DAO service only using entityManager.persist(parent);