borinquenkid commented on code in PR #16532:
URL: https://github.com/apache/grails-core/pull/16532#discussion_r4290190795
##########
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:
Done in 1a09c005b3. The circular shape now warns. It ties on the owner name,
so the property names decide which side logs, keeping it once per relationship.
The Javadoc and the Many-to-Many guide cover it, and
`ManyToManyWithoutOwnerWarningSpec` has a circular case with and without
`belongsTo`.
On the worry that `static belongsTo = ProbeUser` makes both sides owning: I
ran your `ProbeUser` shape three ways, saving through `following`:
| Mapping | `a.following` / `b.followers` after `a.addToFollowing(b);
a.save()` |
|---|---|
| no `belongsTo` | `[]` / `[]` |
| `static belongsTo = ProbeUser` | `[b]` / `[a]` |
| `static belongsTo = [followers: ProbeUser]` | `[b]` / `[a]` |
Both forms store the relationship from both sides, so the existing remedy
text applies unchanged.
The H5 side is #16656 against `7.0.x`: the same circular warning, plus the
Map exclusion you found (H5 now skips a relationship with a Map on either side,
as H7 does here). Once it merges forward, both modules match.
--
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]