Is the element of “initialValue” of @TableGenerator not supported in Hibernate JPA?

纵然是瞬间 提交于 2019-12-01 11:19:52

What it comes to the first value being 1 instead of 1001 that is Hibernate bug HHH-4228, with status Won't fix. Correct first value in your case is 1001 instead of 1000, because initialValue initializes column that stores last value returned (and not the next value to be returned).

Using following in persistence.xml (as also suggested in bug report) will fix problem with first value:

<property name="hibernate.id.new_generator_mappings" value="true"/>

Meaning of allocationSize is likely misunderstood in question. It is not step to increment. It means how many values are allocated with one database query from the table. This is rather optimization to avoid additional query every time when id value is needed for new entity.

Side product is that restart of application causes often holes to the sequence:

  1. initialValue = 1000,allocationSize = 100
  2. Use value 1001 (=> value in valueColumn is updated to 1100).
  3. shutdown and start application
  4. next value will be 1101, not 1002.
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!