Skip to content

Commit

Permalink
HHH-17834 Force version increment for the correct inheritance table
Browse files Browse the repository at this point in the history
  • Loading branch information
mbladel committed May 6, 2024
1 parent fa9e87c commit 3bbc90f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2065,45 +2065,9 @@ protected GeneratedValuesProcessor createGeneratedValuesProcessor(

@Override
public Object forceVersionIncrement(Object id, Object currentVersion, SharedSessionContractImplementor session) {
if ( superMappingType != null ) {
return superMappingType.getEntityPersister().forceVersionIncrement( id, currentVersion, session );
}

assert getMappedTableDetails().getTableName().equals( getVersionedTableName() );
final Object nextVersion = calculateNextVersion( id, currentVersion, 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;
}

Expand All @@ -2113,12 +2077,8 @@ public Object forceVersionIncrement(
Object currentVersion,
boolean batching,
SharedSessionContractImplementor session) throws HibernateException {
if ( superMappingType != null ) {
return superMappingType.getEntityPersister().forceVersionIncrement( id, currentVersion, session );
}

assert getMappedTableDetails().getTableName().equals( getVersionedTableName() );
final Object nextVersion = calculateNextVersion( id, currentVersion, session );

updateCoordinator.forceVersionIncrement( id, currentVersion, nextVersion, batching, session );
return nextVersion;
}
Expand Down Expand Up @@ -2155,17 +2115,6 @@ private Object calculateNextVersion(Object id, Object currentVersion, SharedSess
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
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.hibernate.cache.spi.access.EntityDataAccess;
import org.hibernate.cache.spi.access.NaturalIdDataAccess;
import org.hibernate.dialect.Dialect;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.internal.DynamicFilterAliasGenerator;
import org.hibernate.internal.FilterAliasGenerator;
import org.hibernate.internal.util.collections.ArrayHelper;
Expand Down Expand Up @@ -1082,6 +1083,26 @@ public int determineTableNumberForColumn(String columnName) {
);
}

@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
protected EntityVersionMapping generateVersionMapping(
Supplier<?> templateInstanceCreator,
Expand Down

0 comments on commit 3bbc90f

Please sign in to comment.