Hibernate在使用序列时会生成负面的id值 [英] Hibernate generates negative id values when using a sequence

查看:107
本文介绍了Hibernate在使用序列时会生成负面的id值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



$ $ $
@SequenceGenerator(name =SEQ_ACE_WORKERS_QUEUE_STATS_ID ,sequenceName =SEQ_ACE_WORKERS_QUEUE_STATS_ID,allocationSize = 500)
@GeneratedValue(strategy = GenerationType.SEQUENCE,generator =SEQ_ACE_WORKERS_QUEUE_STATS_ID)
@Column(name =ID)
私人长ID ;

当我们在Jboss 4.2.3上运行它时,它运行良好并生成了正确的ID(从1000 +)



现在我们转移到jboss 7.1.1并生成负ID! (从-498开始并上涨)

任何想法为什么会发生这种情况? / div>

从JBoss 6.1迁移到JBoss 7.1时,我遇到了这个问题。根据JBoss AS 7.1 JPA文档(

#JPAReferenceGuide-Persistenceunitpropertiesrel =noreferrer> https://docs.jboss.org/author/display/AS71/JPA+Reference+Guide#JPAReferenceGuide-Persistenceunitproperties ),



JBoss 7.1会自动设置多个hibernate属性。其中一个属性是 hibernate.id.new_generator_mappings ,它激活使用不同算法并且不向后兼容的新ID生成器。在persistence.xml文件中将此属性设置为false将恢复旧的ID生成器行为。


$ b hibernate 4文档还包含有关新ID生成器的信息: http://docs.jboss.org /hibernate/core/4.0/manual/en-US/html_single/#mapping-declaration-id-generator

hibernate文档明确指出,默认情况下,新的ID生成器未启用,但是,如上所述,JBoss 7.1会自动启用它们。 $ b

I have a class with the following definition:

@Id
@SequenceGenerator(name = "SEQ_ACE_WORKERS_QUEUE_STATS_ID", sequenceName = "SEQ_ACE_WORKERS_QUEUE_STATS_ID", allocationSize = 500)
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "SEQ_ACE_WORKERS_QUEUE_STATS_ID")
@Column(name = "ID")
private long Id;

When we ran it on Jboss 4.2.3 it worked fine and generated the proper ID's (starting from 1000+)

Now we moved to jboss 7.1.1 and it generates negative ID's! (starting from -498 and going up)

Any idea why this might happen?

解决方案

I just ran into this issue when migrating from JBoss 6.1 to JBoss 7.1.

According to the JBoss AS 7.1 JPA documentation ( https://docs.jboss.org/author/display/AS71/JPA+Reference+Guide#JPAReferenceGuide-Persistenceunitproperties),

JBoss 7.1 automatically sets several hibernate properties. One of the properties being set is hibernate.id.new_generator_mappings which activates new ID generators that use different algorithms and are not backwards compatible. Setting this property to false in your persistence.xml file will restore the old ID generator behavior.

The hibernate 4 documentation also has information regarding the new ID generators: http://docs.jboss.org/hibernate/core/4.0/manual/en-US/html_single/#mapping-declaration-id-generator.

The hibernate documentation clearly states that the new ID generators are not enabled by default, but, as noted above, JBoss 7.1 is automatically enabling them.

这篇关于Hibernate在使用序列时会生成负面的id值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆