How to use existing Oracle sequence to generate id in hibernate?

后端 未结 10 1091
夕颜
夕颜 2020-12-04 19:53

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:<

10条回答
  •  感动是毒
    2020-12-04 20:25

    allocationSize and incrementBy are completely different things.

    Hibernate is of course using your sequence created in DB but depending on allocationSize you might find gap in generated value.

    For example- Let assume current sequence value is 5, increment by 1 in db, and allocationSize default 50.

    Now you want to save a collection of 3 element through hibernate, then Hibernate will assign generated id 250, 251, 252

    This is for optimization purpose. Hibernate doesn't have to go back to db and fetch next incremented value.

    If you don't want this just setting allocationSize = 1 as already answered will do the purpose

提交回复
热议问题