views:

382

answers:

1

I have legacy oracle db with a sequence named 'PRODUCT_ID_SEQ'. And here the mapping of Product class for which I need generate correct ids:

public class Product {
   @GeneratedValue(strategy = GenerationType.SEQUENCE, 
                       generator = "etailerRaw_seq")
   @SequenceGenerator(name = "etailerRaw_seq", 
                      sequenceName = "'PRODUCT_ID_SEQ")
   private Long id;

   ...
}

But looks like ids are generated with an interval of 50, like 1000, 1050, 1100 etc. This corresponds to the default value of allocationSize property = 50. So that means that hibernate doesn't actually use the sequence which is already defined in the db.

How do I make hibernate use the sequence?

A: 

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.

rsilva