According to Section 11.1.48 SequenceGenerator Annotation
the JPA 2.1 Specification:
Name generator scope globally for storage unit (for all types of generators).
Thus, you cannot create duplicate generators.
If you try to add the following two objects:
@Entity(name = "Post") public static class Post { @Id @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "pooled") @GenericGenerator( name = "pooled", strategy = "org.hibernate.id.enhanced.SequenceStyleGenerator", parameters = { @Parameter(name = "sequence_name", value = "sequence"), @Parameter(name = "initial_value", value = "1"), @Parameter(name = "increment_size", value = "5"), } ) private Long id; } @Entity(name = "Announcement") public static class Announcement { @Id @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "pooled") @GenericGenerator( name = "pooled", strategy = "org.hibernate.id.enhanced.SequenceStyleGenerator", parameters = { @Parameter(name = "sequence_name", value = "sequence"), @Parameter(name = "initial_value", value = "1"), @Parameter(name = "increment_size", value = "10"), } ) private Long id; }
Hibernate will generate the following error message:
Multiple references to the database sequence [sequence] were found trying to establish conflicting values ββfor the "increment size". Found [10] and [5]
This is because the identifier generator is global, and the two sequence configurations conflict.
source share