While trying to migrate from Hibernate 5.0.12 to a newer version (in this case 5.2.18) I observed a change in behaviour for multi-table entities (e.g. mapping with join table for some attributes), which can lead to StaleStateExceptions since 5.2.15. Older versions like 5.2.14 or 5.0.12 do not fail but succeed.
I will attach a failing test case for 5.2.18, but it also fails for recent 5.3.x and 5.4.x versions, when you change the Hibernate version in the POM file. The test case does not fail for version 5.2.14 and 5.0.12, for example. So, I think this regression was introduced in version 5.2.15, in particular by issue HHH-2558. Updates to joined tables couldn't be batched in older versions, but HHH-2558 introduced changes in this regard.
Hibernate 5.0.12 generates this code in the test case: {code} Hibernate: update company set version=?, name=? where id=? and version=? Hibernate: update company_tax set legalForm=?, bufa=?, number=? where company=? Hibernate: insert into company_tax (legalForm, bufa, number, company) values (?, ?, ?, ?) {code}
The update to the company_tax table will fail, but then an insert will be generated.
Hibernate 5..2.18 generates this code in the test case: {code} Hibernate: update company set version=?, name=? where id=? and version=? Hibernate: update company_tax set legalForm=?, bufa=?, number=? where company=? {code} 2019-04-05 15:45:44 INFO AbstractBatchImpl:193 - HHH000010: On release of batch it still contained JDBC statements 2019-04-05 15:45:44 ERROR BatchingBatch:132 - HHH000315: Exception executing batch [org.hibernate.StaleStateException: Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1], SQL: update company_tax set legalForm=?, bufa=?, number=? where company=?
Here, the update to the company_tax table is batched and fails with an StaleStateException; an insert is not tried anymore, thus failing the test case.
|
|