Reputation: 265
I currently use this approach for generating ids:
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
The effect is, when I save enity of type A it gets the id '1', then I save Enity B and it gets id '2' (instead of 1, because its another entity type), then I save an entity of type A again and it gets id '3' (instead of 2).
What I would like is, that Hibernate counts the ID sequence for every Entity-Type for its own. Is that possible?
Upvotes: 2
Views: 743
Reputation: 16430
Just define different sequences for every entity type. Also see https://docs.oracle.com/javaee/6/api/javax/persistence/SequenceGenerator.html
Upvotes: 0