borinquenkid opened a new issue, #16634:
URL: https://github.com/apache/grails-core/issues/16634

   ## What happens
   
   An entity that is embedded in another and also declares a `hasMany` is bound 
twice: once as a component of its holder and once as an entity of its own.
   
   ```groovy
   @Entity class EmbeddedHolder { EmbeddedWithMany embed; static embedded = 
['embed'] }
   @Entity class EmbeddedWithMany { static hasMany = [members: EmbeddedMember] }
   @Entity class EmbeddedMember { String name }
   ```
   
   `GormMappingConfigurationStrategy.getOrCreateEmbeddedEntity` returns the 
same `PersistentEntity` when the embedded type is itself an `@Entity`, so the 
standalone binding is always there, even if `EmbeddedWithMany` is never used on 
its own. Both bindings resolve the same join table name 
(`TableForManyCalculator` names it from the property's owner), and 
`mappings.addTable` hands back the same `Table` for both. The standalone 
collection's key therefore ends up with the holder's foreign key.
   
   ## Why it matters
   
   The session factory now builds (#16617 fixes the `Collection key not bound` 
failure), but the two bindings still share one join table and one key. Anything 
that relies on the standalone `EmbeddedWithMany` collection being independent 
of the holder's would be wrong.
   
   ## Expected
   
   An embedded entity's `hasMany` should be bound for the component only, or 
the two bindings should not share a table and key.
   
   ## Found in
   
   Review of #16617 (Hibernate 7, 8.0.x).


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