Hibernate allocationSize and generated steps > 1 with Oracle Sequence

陌路散爱 提交于 2020-05-28 05:42:13

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!