jdaugherty commented on code in PR #16532:
URL: https://github.com/apache/grails-core/pull/16532#discussion_r4294715860
##########
grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/binder/CollectionBinder.java:
##########
@@ -212,6 +219,37 @@ 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. A Map-valued side is never inverse once its
second pass has run, because
+ * {@code MapSecondPassBinder} makes it write the join table, so a
relationship with a Map on either side is
+ * stored and gets no warning.
+ */
+ private void warnIfManyToManyHasNoOwningSide(HibernateToManyProperty
property) {
+ if (!(property instanceof HibernateManyToManyProperty manyToMany) ||
+ !manyToMany.isBidirectional() || manyToMany.isCircular()) {
Review Comment:
Confirmed at 1a09c005b3. The circular shape now warns once, from the
`followers` side by the property-name tie-break, and the `WarnCircularOwned`
case stores the relationship from both sides. I also checked the cascade that
`static belongsTo = User` brings with it:
`HibernateToManyProperty.getImpliedCascadeBehavior` gives a many-to-many side
`save-update` whether or not it is correctly owned, so the owned class picks up
no delete cascade. Nothing further here.
--
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]