I have legacy Oracle db with a sequence named PRODUCT_ID_SEQ
.
Here is the mapping of Product
class for which I need generate correct ids:<
I had the same issue while upgrading from 3.5.5 to 5.0.6.Final.
I solved it by re-configuring mapping in the HBM file from:
<generator class="sequence">
<param name="sequence">PRODUCT_ID_SEQ</param>
</generator>
to:
<generator class="org.hibernate.id.enhanced.SequenceStyleGenerator">
<param name="prefer_sequence_per_entity">true</param>
<param name="optimizer">none</param>
<param name="increment_size">1</param>
<param name="sequence_name">PRODUCT_ID_SEQ</param>
</generator>
I use following on PostgreSQL and works just fine.
@Id
@GeneratedValue(generator = "my_gen")
@SequenceGenerator(name = "my_gen", sequenceName = "my_seq_in_db")
private int userId;
I'm not used to use annotations, this is what I have in my *.hbm.xml:
<id name="id" type="java.lang.Integer">
<column name="ID_PRODUCT" />
<generator class="sequence-identity" >
<param name="sequence">PRODUCT_ID_SEQ</param>
</generator>
</id>
You can easily map this to annotations. The generator sequence-identity uses auto increment with sequences.
The answer to the original question:
@SequenceGenerator(name="EL_SEQ", sequenceName="EL_SEQ",allocationSize=1)
It is allocationSize
that sets the value to increment by.