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

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

问题描述

我有一个定义如下的类:

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;

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

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

现在我们迁移到 jboss 7.1.1,它会生成负 ID!(从-498开始向上)

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?

推荐答案

我刚从 JBoss 6.1 迁移到 JBoss 7.1 时遇到了这个问题.

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

根据 JBoss AS 7.1 JPA 文档(https://docs.jboss.org/author/display/AS71/JPA+Reference+Guide#JPAReferenceGuide-Persistenceunitproperties),

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

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

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.

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

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.

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

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天全站免登陆