HHH-16297 Removing an element from a collection of elements removes the whole collection

This commit is contained in:
Andrea Boriero 2023-03-14 13:27:46 +01:00 committed by Christian Beikov
parent b56be6cdab
commit e9ba27e88f
3 changed files with 33 additions and 22 deletions

View File

@ -1337,6 +1337,7 @@ public class MappingModelCreationHelper {
basicElement.isColumnInsertable( 0 ),
basicElement.isColumnUpdateable( 0 ),
basicElement.isPartitionKey(),
true, // element collection does not support null elements
dialect,
creationProcess.getSqmFunctionRegistry()
);

View File

@ -9,14 +9,12 @@ package org.hibernate.metamodel.mapping.internal;
import java.util.Locale;
import org.hibernate.dialect.Dialect;
import org.hibernate.mapping.BasicValue;
import org.hibernate.mapping.Column;
import org.hibernate.mapping.Selectable;
import org.hibernate.metamodel.mapping.JdbcMapping;
import org.hibernate.metamodel.mapping.SelectableMapping;
import org.hibernate.metamodel.mapping.SelectablePath;
import org.hibernate.query.sqm.function.SqmFunctionRegistry;
import org.hibernate.type.BasicType;
import org.hibernate.type.spi.TypeConfiguration;
/**
@ -90,6 +88,32 @@ public class SelectableMappingImpl extends SqlTypedMappingImpl implements Select
);
}
public static SelectableMapping from(
final String containingTableExpression,
final Selectable selectable,
final JdbcMapping jdbcMapping,
final TypeConfiguration typeConfiguration,
boolean insertable,
boolean updateable,
boolean partitioned,
boolean forceNotNullable,
final Dialect dialect,
final SqmFunctionRegistry sqmFunctionRegistry) {
return from(
containingTableExpression,
selectable,
null,
jdbcMapping,
typeConfiguration,
insertable,
updateable,
partitioned,
forceNotNullable,
dialect,
sqmFunctionRegistry
);
}
public static SelectableMapping from(
final String containingTableExpression,
final Selectable selectable,
@ -105,14 +129,12 @@ public class SelectableMappingImpl extends SqlTypedMappingImpl implements Select
containingTableExpression,
selectable,
parentPath,
selectable instanceof Column
? ( (Column) selectable ).getQuotedName( dialect )
: selectable.getText(),
jdbcMapping,
typeConfiguration,
insertable,
updateable,
partitioned,
false,
dialect,
sqmFunctionRegistry
);
@ -122,12 +144,12 @@ public class SelectableMappingImpl extends SqlTypedMappingImpl implements Select
final String containingTableExpression,
final Selectable selectable,
final SelectablePath parentPath,
final String selectableName,
final JdbcMapping jdbcMapping,
final TypeConfiguration typeConfiguration,
boolean insertable,
boolean updateable,
boolean partitioned,
boolean forceNotNullable,
final Dialect dialect,
final SqmFunctionRegistry sqmFunctionRegistry) {
final String columnExpression;
@ -135,6 +157,7 @@ public class SelectableMappingImpl extends SqlTypedMappingImpl implements Select
final Long length;
final Integer precision;
final Integer scale;
final String selectableName;
final boolean isNullable;
if ( selectable.isFormula() ) {
columnExpression = selectable.getTemplate( dialect, typeConfiguration, sqmFunctionRegistry );
@ -143,6 +166,7 @@ public class SelectableMappingImpl extends SqlTypedMappingImpl implements Select
precision = null;
scale = null;
isNullable = true;
selectableName = selectable.getText();
}
else {
Column column = (Column) selectable;
@ -152,7 +176,8 @@ public class SelectableMappingImpl extends SqlTypedMappingImpl implements Select
precision = column.getPrecision();
scale = column.getScale();
isNullable = column.isNullable();
isNullable = forceNotNullable ? false : column.isNullable();
selectableName = column.getQuotedName( dialect );
}
return new SelectableMappingImpl(
containingTableExpression,

View File

@ -10,7 +10,6 @@ import java.io.Serializable;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
@ -193,7 +192,6 @@ public abstract class AbstractCollectionPersister
protected final String[] elementFormulas;
protected final boolean[] elementColumnIsGettable;
protected final boolean[] elementColumnIsSettable;
protected final boolean[] elementColumnIsInPrimaryKey;
protected final String[] indexColumnAliases;
protected final String[] elementColumnAliases;
protected final String[] keyColumnAliases;
@ -376,9 +374,7 @@ public abstract class AbstractCollectionPersister
elementFormulas = new String[elementSpan];
elementColumnIsSettable = new boolean[elementSpan];
elementColumnIsGettable = new boolean[elementSpan];
elementColumnIsInPrimaryKey = new boolean[elementSpan];
boolean isPureFormula = true;
boolean hasNotNullableColumns = false;
boolean oneToMany = collectionBootDescriptor.isOneToMany();
boolean[] columnInsertability = null;
if ( !oneToMany ) {
@ -415,23 +411,12 @@ public abstract class AbstractCollectionPersister
// Preserves legacy non-@ElementCollection behavior
elementColumnIsSettable[j] = true;
}
elementColumnIsInPrimaryKey[j] = !col.isNullable();
if ( !col.isNullable() ) {
hasNotNullableColumns = true;
}
isPureFormula = false;
}
j++;
}
elementIsPureFormula = isPureFormula;
// workaround, for backward compatibility of sets with no
// not-null columns, assume all columns are used in the
// row locator SQL
if ( !hasNotNullableColumns ) {
Arrays.fill( elementColumnIsInPrimaryKey, true );
}
// INDEX AND ROW SELECT
hasIndex = collectionBootDescriptor.isIndexed();