HHH-16297 Removing an element from a collection of elements removes the whole collection
This commit is contained in:
parent
f5171a99a6
commit
952ad9cd8d
|
@ -1337,6 +1337,7 @@ public class MappingModelCreationHelper {
|
||||||
basicElement.isColumnInsertable( 0 ),
|
basicElement.isColumnInsertable( 0 ),
|
||||||
basicElement.isColumnUpdateable( 0 ),
|
basicElement.isColumnUpdateable( 0 ),
|
||||||
basicElement.isPartitionKey(),
|
basicElement.isPartitionKey(),
|
||||||
|
true, // element collection does not support null elements
|
||||||
dialect,
|
dialect,
|
||||||
creationProcess.getSqmFunctionRegistry()
|
creationProcess.getSqmFunctionRegistry()
|
||||||
);
|
);
|
||||||
|
|
|
@ -9,14 +9,12 @@ package org.hibernate.metamodel.mapping.internal;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
import org.hibernate.dialect.Dialect;
|
import org.hibernate.dialect.Dialect;
|
||||||
import org.hibernate.mapping.BasicValue;
|
|
||||||
import org.hibernate.mapping.Column;
|
import org.hibernate.mapping.Column;
|
||||||
import org.hibernate.mapping.Selectable;
|
import org.hibernate.mapping.Selectable;
|
||||||
import org.hibernate.metamodel.mapping.JdbcMapping;
|
import org.hibernate.metamodel.mapping.JdbcMapping;
|
||||||
import org.hibernate.metamodel.mapping.SelectableMapping;
|
import org.hibernate.metamodel.mapping.SelectableMapping;
|
||||||
import org.hibernate.metamodel.mapping.SelectablePath;
|
import org.hibernate.metamodel.mapping.SelectablePath;
|
||||||
import org.hibernate.query.sqm.function.SqmFunctionRegistry;
|
import org.hibernate.query.sqm.function.SqmFunctionRegistry;
|
||||||
import org.hibernate.type.BasicType;
|
|
||||||
import org.hibernate.type.spi.TypeConfiguration;
|
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(
|
public static SelectableMapping from(
|
||||||
final String containingTableExpression,
|
final String containingTableExpression,
|
||||||
final Selectable selectable,
|
final Selectable selectable,
|
||||||
|
@ -105,14 +129,12 @@ public class SelectableMappingImpl extends SqlTypedMappingImpl implements Select
|
||||||
containingTableExpression,
|
containingTableExpression,
|
||||||
selectable,
|
selectable,
|
||||||
parentPath,
|
parentPath,
|
||||||
selectable instanceof Column
|
|
||||||
? ( (Column) selectable ).getQuotedName( dialect )
|
|
||||||
: selectable.getText(),
|
|
||||||
jdbcMapping,
|
jdbcMapping,
|
||||||
typeConfiguration,
|
typeConfiguration,
|
||||||
insertable,
|
insertable,
|
||||||
updateable,
|
updateable,
|
||||||
partitioned,
|
partitioned,
|
||||||
|
false,
|
||||||
dialect,
|
dialect,
|
||||||
sqmFunctionRegistry
|
sqmFunctionRegistry
|
||||||
);
|
);
|
||||||
|
@ -122,12 +144,12 @@ public class SelectableMappingImpl extends SqlTypedMappingImpl implements Select
|
||||||
final String containingTableExpression,
|
final String containingTableExpression,
|
||||||
final Selectable selectable,
|
final Selectable selectable,
|
||||||
final SelectablePath parentPath,
|
final SelectablePath parentPath,
|
||||||
final String selectableName,
|
|
||||||
final JdbcMapping jdbcMapping,
|
final JdbcMapping jdbcMapping,
|
||||||
final TypeConfiguration typeConfiguration,
|
final TypeConfiguration typeConfiguration,
|
||||||
boolean insertable,
|
boolean insertable,
|
||||||
boolean updateable,
|
boolean updateable,
|
||||||
boolean partitioned,
|
boolean partitioned,
|
||||||
|
boolean forceNotNullable,
|
||||||
final Dialect dialect,
|
final Dialect dialect,
|
||||||
final SqmFunctionRegistry sqmFunctionRegistry) {
|
final SqmFunctionRegistry sqmFunctionRegistry) {
|
||||||
final String columnExpression;
|
final String columnExpression;
|
||||||
|
@ -135,6 +157,7 @@ public class SelectableMappingImpl extends SqlTypedMappingImpl implements Select
|
||||||
final Long length;
|
final Long length;
|
||||||
final Integer precision;
|
final Integer precision;
|
||||||
final Integer scale;
|
final Integer scale;
|
||||||
|
final String selectableName;
|
||||||
final boolean isNullable;
|
final boolean isNullable;
|
||||||
if ( selectable.isFormula() ) {
|
if ( selectable.isFormula() ) {
|
||||||
columnExpression = selectable.getTemplate( dialect, typeConfiguration, sqmFunctionRegistry );
|
columnExpression = selectable.getTemplate( dialect, typeConfiguration, sqmFunctionRegistry );
|
||||||
|
@ -143,6 +166,7 @@ public class SelectableMappingImpl extends SqlTypedMappingImpl implements Select
|
||||||
precision = null;
|
precision = null;
|
||||||
scale = null;
|
scale = null;
|
||||||
isNullable = true;
|
isNullable = true;
|
||||||
|
selectableName = selectable.getText();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Column column = (Column) selectable;
|
Column column = (Column) selectable;
|
||||||
|
@ -152,7 +176,8 @@ public class SelectableMappingImpl extends SqlTypedMappingImpl implements Select
|
||||||
precision = column.getPrecision();
|
precision = column.getPrecision();
|
||||||
scale = column.getScale();
|
scale = column.getScale();
|
||||||
|
|
||||||
isNullable = column.isNullable();
|
isNullable = forceNotNullable ? false : column.isNullable();
|
||||||
|
selectableName = column.getQuotedName( dialect );
|
||||||
}
|
}
|
||||||
return new SelectableMappingImpl(
|
return new SelectableMappingImpl(
|
||||||
containingTableExpression,
|
containingTableExpression,
|
||||||
|
|
|
@ -10,7 +10,6 @@ import java.io.Serializable;
|
||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
@ -193,7 +192,6 @@ public abstract class AbstractCollectionPersister
|
||||||
protected final String[] elementFormulas;
|
protected final String[] elementFormulas;
|
||||||
protected final boolean[] elementColumnIsGettable;
|
protected final boolean[] elementColumnIsGettable;
|
||||||
protected final boolean[] elementColumnIsSettable;
|
protected final boolean[] elementColumnIsSettable;
|
||||||
protected final boolean[] elementColumnIsInPrimaryKey;
|
|
||||||
protected final String[] indexColumnAliases;
|
protected final String[] indexColumnAliases;
|
||||||
protected final String[] elementColumnAliases;
|
protected final String[] elementColumnAliases;
|
||||||
protected final String[] keyColumnAliases;
|
protected final String[] keyColumnAliases;
|
||||||
|
@ -376,9 +374,7 @@ public abstract class AbstractCollectionPersister
|
||||||
elementFormulas = new String[elementSpan];
|
elementFormulas = new String[elementSpan];
|
||||||
elementColumnIsSettable = new boolean[elementSpan];
|
elementColumnIsSettable = new boolean[elementSpan];
|
||||||
elementColumnIsGettable = new boolean[elementSpan];
|
elementColumnIsGettable = new boolean[elementSpan];
|
||||||
elementColumnIsInPrimaryKey = new boolean[elementSpan];
|
|
||||||
boolean isPureFormula = true;
|
boolean isPureFormula = true;
|
||||||
boolean hasNotNullableColumns = false;
|
|
||||||
boolean oneToMany = collectionBootDescriptor.isOneToMany();
|
boolean oneToMany = collectionBootDescriptor.isOneToMany();
|
||||||
boolean[] columnInsertability = null;
|
boolean[] columnInsertability = null;
|
||||||
if ( !oneToMany ) {
|
if ( !oneToMany ) {
|
||||||
|
@ -415,23 +411,12 @@ public abstract class AbstractCollectionPersister
|
||||||
// Preserves legacy non-@ElementCollection behavior
|
// Preserves legacy non-@ElementCollection behavior
|
||||||
elementColumnIsSettable[j] = true;
|
elementColumnIsSettable[j] = true;
|
||||||
}
|
}
|
||||||
elementColumnIsInPrimaryKey[j] = !col.isNullable();
|
|
||||||
if ( !col.isNullable() ) {
|
|
||||||
hasNotNullableColumns = true;
|
|
||||||
}
|
|
||||||
isPureFormula = false;
|
isPureFormula = false;
|
||||||
}
|
}
|
||||||
j++;
|
j++;
|
||||||
}
|
}
|
||||||
elementIsPureFormula = isPureFormula;
|
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
|
// INDEX AND ROW SELECT
|
||||||
|
|
||||||
hasIndex = collectionBootDescriptor.isIndexed();
|
hasIndex = collectionBootDescriptor.isIndexed();
|
||||||
|
|
Loading…
Reference in New Issue