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:<
If you use javax.persistence.SequenceGenerator, hibernate use hilo and will possibly create large gaps in the sequence. There is a post addressing this problem: https://forum.hibernate.org/viewtopic.php?t=973682
there are two ways to fix this problem
In the SequenceGenerator annotation, add allocationSize = 1, initialValue= 1
instead of using javax.persistence.SequenceGenerator, use org.hibernate.annotations, like this:
@javax.persistence.SequenceGenerator(name = "Question_id_sequence", sequenceName = "S_QUESTION")
@org.hibernate.annotations.GenericGenerator(name="Question_id_sequence", strategy = "sequence", parameters = { @Parameter(name="sequence", value="S_QUESTION") } )
I have tested both ways, which works just fine.