mirror of
https://github.com/hibernate/hibernate-orm
synced 2025-02-17 00:24:57 +00:00
HHH-13355 : StaleStateException for updates to optional secondary table using saveOrUpdate
This commit is contained in:
parent
69dad5fda5
commit
99868fb5f9
@ -3321,7 +3321,18 @@ protected boolean update(
|
|||||||
|
|
||||||
final Expectation expectation = Expectations.appropriateExpectation( updateResultCheckStyles[j] );
|
final Expectation expectation = Expectations.appropriateExpectation( updateResultCheckStyles[j] );
|
||||||
final int jdbcBatchSizeToUse = session.getConfiguredJdbcBatchSize();
|
final int jdbcBatchSizeToUse = session.getConfiguredJdbcBatchSize();
|
||||||
final boolean useBatch = expectation.canBeBatched() && isBatchable() && jdbcBatchSizeToUse > 1;
|
// IMPLEMENTATION NOTE: If Session#saveOrUpdate or #update is used to update an entity, then
|
||||||
|
// Hibernate does not have a database snapshot of the existing entity.
|
||||||
|
// As a result, oldFields will be null.
|
||||||
|
// Don't use a batch if oldFields == null and the jth table is optional (isNullableTable( j ),
|
||||||
|
// because there is no way to know that there is actually a row to update. If the update
|
||||||
|
// was batched in this case, the batch update would fail and there is no way to fallback to
|
||||||
|
// an insert.
|
||||||
|
final boolean useBatch =
|
||||||
|
expectation.canBeBatched() &&
|
||||||
|
isBatchable() &&
|
||||||
|
jdbcBatchSizeToUse > 1 &&
|
||||||
|
( oldFields != null || !isNullableTable( j ) );
|
||||||
if ( useBatch && updateBatchKey == null ) {
|
if ( useBatch && updateBatchKey == null ) {
|
||||||
updateBatchKey = new BasicBatchKey(
|
updateBatchKey = new BasicBatchKey(
|
||||||
getEntityName() + "#UPDATE",
|
getEntityName() + "#UPDATE",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user