jamesfredley commented on code in PR #16701:
URL: https://github.com/apache/grails-core/pull/16701#discussion_r4365978316
##########
grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/secondpass/CollectionKeyColumnUpdater.java:
##########
@@ -36,28 +43,11 @@ public CollectionKeyColumnUpdater(CollectionKeyBinder
collectionKeyBinder) {
this.collectionKeyBinder = collectionKeyBinder;
}
- /** Creates the key, sets it on the collection, and updates its columns. */
+ /** Creates the key, sets it on the collection, and makes its columns
nullable and the key updatable. */
public void bind(HibernateToManyProperty property) {
DependantValue key = collectionKeyBinder.bind(property);
key.getColumns().stream().filter(Objects::nonNull).forEach(column ->
column.setNullable(true));
- Table collectionTable = property.getCollection().getCollectionTable();
- long unidirectionalCount = property.getHibernateOwner()
- .getPersistentPropertiesToBind()
- .stream()
- .filter(HibernateToManyProperty::isBoundAsCollection)
- .map(HibernateToManyProperty.class::cast)
- .filter(p -> !p.isBidirectional())
- .filter(p ->
Objects.equals(p.getCollection().getCollectionTable(), collectionTable))
- .count();
-
- // Collections of basic values or enums
(HibernateToManyCollectionProperty) always keep an updatable key: they
- // have no inverse side, and Hibernate writes no rows for a collection
whose key is not updatable.
- // For entity collections (HibernateToManyEntityProperty) the key is
non-updatable only when the owner has
- // two or more unidirectional to-many properties that share this
collection's join table, the rule for issue
- // 10811. Unidirectional collections with join tables of their own
keep an updatable key, as they have no
- // second key column to leave null. A to-many that is not bound as a
collection (a serializable or user type)
- // has no join table and no Hibernate collection, so it is neither
counted nor asked for one.
- key.setUpdateable(property instanceof
HibernateToManyCollectionProperty || unidirectionalCount <= 1);
+ key.setUpdateable(true);
Review Comment:
When a shared-table set has two elements, removing one deletes both.
Hibernate's row-delete predicate omits the nullable element columns, and `is
not null` does not tell the two elements apart. The pending removal tests in
`SharedJoinTableBulkDeleteSpec` show this. The key used to be non-updatable, so
this path is new.
Fix the row delete, or rewrite the surviving rows, before enabling updates.
Please remove one element and assert the other remains.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]