Hi,
We'd like the application to retrieve a block of IDs from an Oracle sequence and reuse those rather than hit the DB each time to get the sequence value.
We have the ID annotated as follows:
@Id @Column(name="MY_ID", nullable=false, insertable=true, updatable=false) @SequenceGenerator(name="planIdSequence", sequenceName="MY_ID_SEQ", allocationSize=50) @GeneratedValue(strategy=GenerationType.AUTO, generator="planIdSequence") private Long id;
And the sequence in Oracle created as:
create sequence MY_ID_SEQ start with 1 increment by 50 cache 20 nocycle;
However, I'm noticing that each insert into the DB, the ID value is being set to +50. As though it's still going to the DB for each request. Does the allocationSize only work on a per session basis? The service has multiple hosts and multiple threads per host - so if the allocationSize only applies per session and we commit/close after each requests - that would at least explain the behaviour we are seeing.
If that is the case, is there a way to have this applied at a global level, per service instance across multiple threads rather than per session? Another alternative could be to write a custom sequence generator that allows us to do this on an application instance level.
Any help is greatly appreciated, Thanks!
|