borinquenkid commented on code in PR #16532:
URL: https://github.com/apache/grails-core/pull/16532#discussion_r4213507860
##########
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:
Fixed in 8fc0fef2cd: the warning is skipped when either side is Map-valued,
since `MapSecondPassBinder` makes that side write the join table. A regression
covers Map/Set and Map/Map pairs with no `belongsTo`, and another shows the
relationship is stored when written through the Map side.
--
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]