HHH-17834 Force version increment for the correct inheritance table

This commit is contained in:
Marco Belladelli 2024-04-03 11:22:32 +02:00
parent fa9e87c675
commit 3bbc90fb9b
2 changed files with 23 additions and 53 deletions

View File

@ -2065,45 +2065,9 @@ public abstract class AbstractEntityPersister
@Override @Override
public Object forceVersionIncrement(Object id, Object currentVersion, SharedSessionContractImplementor session) { public Object forceVersionIncrement(Object id, Object currentVersion, SharedSessionContractImplementor session) {
if ( superMappingType != null ) { assert getMappedTableDetails().getTableName().equals( getVersionedTableName() );
return superMappingType.getEntityPersister().forceVersionIncrement( id, currentVersion, session );
}
final Object nextVersion = calculateNextVersion( id, currentVersion, session ); final Object nextVersion = calculateNextVersion( id, currentVersion, session );
updateCoordinator.forceVersionIncrement( id, currentVersion, nextVersion, session ); updateCoordinator.forceVersionIncrement( id, currentVersion, nextVersion, session );
// // todo : cache this sql...
// String versionIncrementString = generateVersionIncrementUpdateString();
// PreparedStatement st;
// try {
// st = session
// .getJdbcCoordinator()
// .getStatementPreparer()
// .prepareStatement( versionIncrementString, false );
// try {
// getVersionType().nullSafeSet( st, nextVersion, 1, session );
// getIdentifierType().nullSafeSet( st, id, 2, session );
// getVersionType().nullSafeSet( st, currentVersion, 2 + getIdentifierColumnSpan(), session );
// int rows = session.getJdbcCoordinator().getResultSetReturn().executeUpdate( st );
// if ( rows != 1 ) {
// throw new StaleObjectStateException( getEntityName(), id );
// }
// }
// finally {
// session.getJdbcCoordinator().getLogicalConnection().getResourceRegistry().release( st );
// session.getJdbcCoordinator().afterStatementExecution();
// }
// }
// catch (SQLException sqle) {
// throw session.getJdbcServices().getSqlExceptionHelper().convert(
// sqle,
// "could not retrieve version: " +
// MessageHelper.infoString( this, id, getFactory() ),
// getVersionSelectString()
// );
// }
return nextVersion; return nextVersion;
} }
@ -2113,12 +2077,8 @@ public abstract class AbstractEntityPersister
Object currentVersion, Object currentVersion,
boolean batching, boolean batching,
SharedSessionContractImplementor session) throws HibernateException { SharedSessionContractImplementor session) throws HibernateException {
if ( superMappingType != null ) { assert getMappedTableDetails().getTableName().equals( getVersionedTableName() );
return superMappingType.getEntityPersister().forceVersionIncrement( id, currentVersion, session );
}
final Object nextVersion = calculateNextVersion( id, currentVersion, session ); final Object nextVersion = calculateNextVersion( id, currentVersion, session );
updateCoordinator.forceVersionIncrement( id, currentVersion, nextVersion, batching, session ); updateCoordinator.forceVersionIncrement( id, currentVersion, nextVersion, batching, session );
return nextVersion; return nextVersion;
} }
@ -2155,17 +2115,6 @@ public abstract class AbstractEntityPersister
return nextVersion; return nextVersion;
} }
// private String generateVersionIncrementUpdateString() {
// final Update update = new Update( getFactory().getJdbcServices().getDialect() ).setTableName( getTableName( 0 ) );
// if ( getFactory().getSessionFactoryOptions().isCommentsEnabled() ) {
// update.setComment( "forced version increment" );
// }
// update.addColumn( getVersionColumnName() );
// update.addPrimaryKeyColumns( rootTableKeyColumnNames );
// update.setVersionColumnName( getVersionColumnName() );
// return update.toStatementString();
// }
/** /**
* Retrieve the version number * Retrieve the version number
*/ */

View File

@ -22,6 +22,7 @@ import org.hibernate.boot.model.relational.SqlStringGenerationContext;
import org.hibernate.cache.spi.access.EntityDataAccess; import org.hibernate.cache.spi.access.EntityDataAccess;
import org.hibernate.cache.spi.access.NaturalIdDataAccess; import org.hibernate.cache.spi.access.NaturalIdDataAccess;
import org.hibernate.dialect.Dialect; import org.hibernate.dialect.Dialect;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.internal.DynamicFilterAliasGenerator; import org.hibernate.internal.DynamicFilterAliasGenerator;
import org.hibernate.internal.FilterAliasGenerator; import org.hibernate.internal.FilterAliasGenerator;
import org.hibernate.internal.util.collections.ArrayHelper; import org.hibernate.internal.util.collections.ArrayHelper;
@ -1082,6 +1083,26 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister {
); );
} }
@Override
public Object forceVersionIncrement(Object id, Object currentVersion, SharedSessionContractImplementor session) {
if ( getSuperMappingType() != null ) {
return getSuperMappingType().getEntityPersister().forceVersionIncrement( id, currentVersion, session );
}
return super.forceVersionIncrement( id, currentVersion, session );
}
@Override
public Object forceVersionIncrement(
Object id,
Object currentVersion,
boolean batching,
SharedSessionContractImplementor session) throws HibernateException {
if ( getSuperMappingType() != null ) {
return getSuperMappingType().getEntityPersister().forceVersionIncrement( id, currentVersion, session );
}
return super.forceVersionIncrement( id, currentVersion, batching, session );
}
@Override @Override
protected EntityVersionMapping generateVersionMapping( protected EntityVersionMapping generateVersionMapping(
Supplier<?> templateInstanceCreator, Supplier<?> templateInstanceCreator,