简体   繁体   English

更新依赖项后使用TableGenerator的ConstraintViolationException

[英]ConstraintViolationException using TableGenerator after updating dependencies

After updating dependencies from Spring 4.1.6.RELEASE to 5.1.4.RELEASE and Hibernate 4.3.9.Final to 5.4.1.Final, some of my test cases started failing with ConstraintViolationException on the primary key. 在将依赖项从Spring 4.1.6.RELEASE更新到5.1.4.RELEASE并将Hibernate 4.3.9.Final更新到5.4.1.Final之后,我的一些测试用例因主键上的ConstraintViolationException而开始失败。

Due to historical reasons we are generating the primary like so: 由于历史原因,我们生成主要像这样:

@Id
@GeneratedValue(strategy = GenerationType.TABLE, generator = "NAME_HERE")
@TableGenerator(name = "NAME_HERE", table = "SEQUENCE_TABLE_NAME", pkColumnName = "Name", pkColumnValue = "ENTITY_NAME", valueColumnName = "VALUE_COLUMN_NAME", allocationSize = 100)

While using the application normally it does not seem to be a problem, however when running tests it does. 正常情况下使用该应用程序似乎没有问题,但是在运行测试时确实存在问题。

I have noticed that the ConstraintViolationException only occurs for tables where multiple values are inserted within the same test case. 我注意到,ConstraintViolationException仅发生在在同一测试用例中插入多个值的表中。 So i'm thinking the rows are somehow assigned the same primary key. 所以我认为行以某种方式分配了相同的主键。

Running the tests locally it does not seem to be a problem, so it could also have something to do with how the tests are run on the build server. 在本地运行测试似乎不是问题,因此它也可能与在构建服务器上运行测试的方式有关。 However it was not a problem before upgrading dependencies. 但是,在升级依赖项之前这不是问题。

I have checked that the sequence values are higher than the latest value in the database, but again this was not a problem before upgrading dependencies. 我检查了序列值是否高于数据库中的最新值,但是在升级依赖项之前,这也不是问题。

I am hoping to jolt someones memory :-) 我希望震动某人的记忆:-)

i found this: Hibernate, @SequenceGenerator and allocationSize 我发现了这一点: Hibernate,@ SequenceGenerator和allocationSize

Which made me find "hibernate.id.new_generator_mappings" 这让我找到了“ hibernate.id.new_generator_mappings”

As per: https://docs.jboss.org/hibernate/orm/5.0/userguide/html_single/Hibernate_User_Guide.html#configurations 按照: https : //docs.jboss.org/hibernate/orm/5.0/userguide/html_single/Hibernate_User_Guide.html#configurations

*Setting which indicates whether or not the new org.hibernate.id.IdentifierGenerator are used for AUTO, TABLE and SEQUENCE. *此设置指示新的org.hibernate.id.IdentifierGenerator是否用于AUTO,TABLE和SEQUENCE。

Existing applications may want to disable this (set it false) for upgrade compatibility from 3.x and 4.x to 5.x.* 现有应用程序可能想要禁用此功能(将其设置为false),以实现从3.x和4.x到5.x的升级兼容性。*

Setting this to false solved the problem. 将此设置为false可解决问题。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用Spring数据存储库在保存级联中更新子对象会导致ConstraintViolationException - Updating a child object in a save cascade result in ConstraintViolationException using spring data repository 更新android支持库依赖项后的问题 - Issues after updating android support library dependencies 使用@TableGenerator的JPA id生成表的动态值 - Dynamic values for JPA id generation table using @TableGenerator java-更改参数数量后休眠ConstraintViolationException - java - hibernate ConstraintViolationException after changing number of parameters 使用许多关系的derby +休眠ConstraintViolationException - derby + hibernate ConstraintViolationException using manytomany relationships ConstraintViolationException:使用Spring,HSQL和Hibernate时为NOT NULL - ConstraintViolationException: NOT NULL when using Spring, HSQL and Hibernate @TableGenerator for mybatis - @TableGenerator for mybatis 更新Gradle依赖项后生成错误。 嫌疑犯#1是火力发源地 - Build errors after updating Gradle dependencies. Suspect #1 is firebase Hibernate 从 5 迁移到 5.5 后,将实体添加到集合会导致 ConstraintViolationException - After Hibernate migration from 5 to 5.5 adding entities to collections causes ConstraintViolationException 使用@TableGenerator的JPA EclipseLink。 事务回滚后,为什么分配给id的值不为null? - JPA EclipseLink with @TableGenerator. Why is the value assigned to id not null after transaction rollback?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM