问题
here is what I am trying to achieve:
I have an Oracle Sequence defined as follows:
CREATE SEQUENCE "SEQ_ENDKUNDE" MINVALUE 1 MAXVALUE 9999999999999999999999999999 INCREMENT BY 1000 START WITH 1 CACHE 20 GLOBAL ;
The Ids must be incremented by 1000 due to a complex replication infrastructure. The Hibernate part looks as follows:
@Id
@GeneratedValue(
strategy = GenerationType.SEQUENCE,
generator = "sequence-generator"
)
@SequenceGenerator(
name = "sequence-generator",
sequenceName = "SEQ_ENDKUNDE",
allocationSize = 1
)
private Long id;
This works, but is inefficient since Hiberate has to query for a new Id on every insert.
Does somebody know if there is a way to achieve this behaviour with the pooled or pooled-lo optimzed generator:
@Id
@GeneratedValue(
strategy = GenerationType.SEQUENCE,
generator = "sequence-generator"
)
@GenericGenerator(
name = "sequence-generator",
strategy = "org.hibernate.id.enhanced.SequenceStyleGenerator",
parameters = {
@Parameter(name = "sequence_name", value = "SEQ_ENDKUNDE"),
@Parameter(name = "initial_value", value = "1"),
@Parameter(name = "increment_size", value = "1000"),
@Parameter(name = "optimizer", value = "pooled-lo")
}
)
private Long id;
Problem with this is that Hibernate would generate Ids like 1001,1002,1003...
but what I need is 1001,2001,3001
.
Thanks in advance for any ideas!
来源:https://stackoverflow.com/questions/61203160/hibernate-allocationsize-and-generated-steps-1-with-oracle-sequence