休眠增加起始号码 [英] Hibernate increment starting number
问题描述
我正在使用hibernate将一个实体保存到我的数据库中。目前它是一个德比数据库,但我很快就会将它移动到Oracle DB中。
在我的classname.hbm.xml中我有这样定义的id :
< id name =idtype =long>
< column name =ID/>
< generator class =increment/>
< / id>
如何设置id的起始值?我希望它从10000开始,而不是1开始。 我不认为你可以, IncrementGenerator基于最高主键工作,所以除非你修复了主键(我不建议这样做),否则你会被这个功能所困扰。
会推荐一个不同的策略,它在一组机器中是不安全的...查看Hibernate文档,也许是增强的标识符生成器:
I'm using hibernate to persist an entity to my database. For the moment it's a derby DB, but I will be moving it over to an oracle DB soon.
in my classname.hbm.xml I have the id defined as such:
<id name="id" type="long">
<column name="ID"/>
<generator class="increment"/>
</id>
How do I set the starting value for the id? I'd like it to start at something like 10000 rather than 1.
I don't think you can, it appears that IncrementGenerator works based off the highest primary key so unless you fix your primary keys (which I wouldn't recommend) you're stuck with that functionality.
Would recommend a different strategy, it isn't safe in a cluster of machines either... Look at the Hibernate docs and maybe the enhanced identifier generators:
这篇关于休眠增加起始号码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!