jamesfredley commented on code in PR #16532:
URL: https://github.com/apache/grails-core/pull/16532#discussion_r4215266471


##########
grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/binder/CollectionBinder.java:
##########
@@ -212,6 +217,34 @@ private void bindCollectionTable(HibernateToManyProperty 
property, Collection co
         collection.setCollectionTable(
                 mappings.addTable(schemaName, catalogName, tableName, null, 
false, metadataBuildingContext, false));
         collection.setInverse(property.isBidirectional() && 
!property.isOwningSide());
+        if (collection.isInverse()) {
+            warnIfManyToManyHasNoOwningSide(property);
+        }
+    }
+
+    /**
+     * A bidirectional many-to-many is written by its owning side, which 
{@code belongsTo} designates. When neither
+     * side declares {@code belongsTo}, both sides are inverse and the 
relationship is never stored, so warn about it
+     * once per relationship.
+     */
+    private void warnIfManyToManyHasNoOwningSide(HibernateToManyProperty 
property) {
+        if (!(property instanceof HibernateManyToManyProperty manyToMany) ||
+                !manyToMany.isBidirectional() || manyToMany.isCircular()) {
+            return;
+        }
+        Association<?> otherSide = manyToMany.getInverseSide();
+        if (otherSide == null || otherSide.isOwningSide()) {
+            return;
+        }
+        if 
(manyToMany.getOwner().getName().compareTo(otherSide.getOwner().getName()) > 0) 
{
+            return;
+        }
+        LOG.warn("Neither side of the many-to-many between [{}.{}] and [{}.{}] 
declares belongsTo, so the relationship " +

Review Comment:
   The latest commit skips this warning when either side is a Map. The second 
pass still makes that Map side non-inverse, so it writes the join table, and 
the new spec covers both the warning and a persistence round trip.



-- 
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]

Reply via email to