borinquenkid opened a new pull request, #16617:
URL: https://github.com/apache/grails-core/pull/16617
## Problem
An entity that is also embedded in another can declare a `hasMany`. With
```groovy
@Entity class EmbeddedHolder { EmbeddedWithMany embed; static embedded =
['embed'] }
@Entity class EmbeddedWithMany { static hasMany = [members: EmbeddedMember] }
@Entity class EmbeddedMember { String name }
```
the session factory fails to build with `Collection key not bound` (an NPE
on `Collection.getElement()`).
## Cause
Such an entity is bound twice, once as a component of its holder and once as
an entity, and its `hasMany` property is bound with a different Hibernate
collection each time. The property only remembers the last collection. The
second passes bound `property.getCollection()`, so the collection of the first
binding never got its element and key.
## Fix
`ListSecondPass`, `MapSecondPass` and `SetSecondPass` now keep the
collection they were created for and restore it on the property before binding.
`CollectionBinder` passes it in. The existing two-argument constructors are
kept.
## Tests
`EmbeddedEntityWithHasManySpec` saves and reads back the collection of an
embedded entity. With the four production files reverted the spec fails with
`NullPointerException: Cannot invoke "org.hibernate.mapping.Value.getType()"
because the return value of "org.hibernate.mapping.Collection.getElement()" is
null`. With the fix it passes.
## Why this is separate
It was found while moving the graphql examples to Hibernate 7 and was
sitting inside the Hibernate 5 removal branch (#16350). A removal should only
delete, so the fix lands here on 8.0.x and reaches 9.0.x through the merge-up.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
--
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]