Is there a way to specify distinct sequences for each table in Hibernate, if the ID is defined on a mapped superclass?
All entities in our application extend a super
We use this in the abstract superclass of all of our JPA entities:
@Id
@GeneratedValue(generator = "pooled")
@GenericGenerator(name = "pooled", strategy = "org.hibernate.id.enhanced.TableGenerator", parameters = {
@org.hibernate.annotations.Parameter(name = "value_column_name", value = "sequence_next_hi_value"),
@org.hibernate.annotations.Parameter(name = "prefer_entity_table_as_segment_value", value = "true"),
@org.hibernate.annotations.Parameter(name = "optimizer", value = "pooled-lo"),
@org.hibernate.annotations.Parameter(name = "increment_size", value = "100")})
private Long id;
It's a bit verbose, but it allows setting the prefer_entity_table_as_segment_value
which means you don't need to repeat the id
field or the generator annotations in the subclasses.