Hibernate SequenceGenerator and allocationSize value setting
<p>I am facing an issue with hibernate generated identifier. I am using Sequence Generator to generate my identifier. Database is Oracle 11g and hibernate version 3.6.1. </p>

<p>I am aware that the default allocationSize in hibernate is 50 and hence hibernate makes calls to database every 50 inserts to fetch the identifier. Hence I am changing the allocationSize to 1000 to reduce database calls as below:</p>

<pre><code>    @GeneratedValue(generator = "test_gen", strategy = GenerationType.SEQUENCE)
    @SequenceGenerator(name = "test_gen", sequenceName = "myschema.my_oracle_sequence", allocationSize = 1000)
</code></pre>

<p>There are few issues though. </p>

<p>First, this is an enhancement, hence I cant upgrade the hibernate version to make use of the new sequence generators. </p>

<p>Second, I cant use the below property as this will impact other hibernate entities, which should not be touched by my change.Is there some way to tell hibernate to apply the below property to only one entity?</p>

<pre><code>    hibernate.id.new_generator_mappings=true
</code></pre>

<p>Third, I tried the below hibernate specific mapping. However, I am required to provide an initial value here. If not, it takes initial value as 1 and computes the identifier and I get as expected a Constraint Exception as the identifier has already been used.
I cant provide an initial value here again as the code is already in use and both primary id and nextval of the sequence have moved from their initial values.</p>

<pre><code>    @GenericGenerator(
    name = "sequenceGenerator", 
    strategy = "enhanced-sequence",
    parameters = {
        @org.hibernate.annotations.Parameter(
            name = "optimizer", 
            value = "pooled"
        ),
        @org.hibernate.annotations.Parameter(
            name = "increment_size", 
            value = "500"
        )
    }
)
@GeneratedValue(
    strategy = GenerationType.SEQUENCE, 
    generator = "sequenceGenerator"
)
</code></pre>

<p>Fourth, I cant use the code that I have mentioned in first code block, as I randomly see UniqueConstraintViolationException when inserting the records as has been seen by few other folks.
<a href="https://stackoverflow.com/questions/18993889/jpa-2-sequencegenerator-generatedvalue-producing-unique-constraint-violation">JPA 2 @SequenceGenerator @GeneratedValue producing unique constraint violation</a></p>

<p>With all these constraints, is there any way I can increase the allocationSize so as to improve the records insertion performance. I would inserting around 10-40mn records in a single batch.</p>

<p>Regards,
V</p>