@groovy.transform.Trait @groovy.transform.CompileStatic trait HibernateEntity<D> extends GormEntity<D>
Extends the GormEntity trait adding additional Hibernate specific methods
| Type Params | Return Type | Name and description |
|---|---|---|
|
D |
addTo(java.lang.String associationName, java.lang.Object arg)Overrides GormEntity.addTo to fix "Found two representations of same collection" in Hibernate 7. |
|
static java.util.List<D> |
findAllWithSql(java.lang.CharSequence sql)Finds all objects for the given SQL query. |
|
static java.util.List<D> |
findAllWithSql(java.lang.CharSequence sql, java.util.Map args)Finds all objects for the given SQL query. |
|
static D |
findWithSql(java.lang.CharSequence sql)Finds an entity for the given SQL query. |
|
static D |
findWithSql(java.lang.CharSequence sql, java.util.Map args)Finds an entity for the given SQL query. |
Overrides GormEntity.addTo to fix "Found two representations of same collection"
in Hibernate 7.
H7 uses bytecode-enhanced attribute interception: the entity field for a collection is
physically null until first accessed through the getter. GormEntity.addTo uses
direct field access via EntityReflector, so it sees null and creates a new plain
ArrayList — which collides with the PersistentBag already tracked in the session.
The fix: when the entity is already persisted (has an id) and the field is null, access the
collection through the getter via org.codehaus.groovy.runtime.InvokerHelper. H7's attribute interceptor then
returns the session-tracked PersistentBag. We write it back to the field so the base
addTo finds it and adds directly into the PersistentBag without creating a plain one.
Finds all objects for the given SQL query. Pass a GString to have interpolated values safely bound as named parameters rather than interpolated into the query string.
sql - The SQL queryFinds all objects for the given SQL query. Pass a GString to have interpolated values safely bound as named parameters rather than interpolated into the query string.
sql - The SQL queryargs - Pagination/query settings (max, offset, cache, etc.)Finds an entity for the given SQL query. Pass a GString to have interpolated values safely bound as named parameters rather than interpolated into the query string.
sql - The SQL queryFinds an entity for the given SQL query. Pass a GString to have interpolated values safely bound as named parameters rather than interpolated into the query string.
sql - The SQL queryargs - Pagination/query settings (max, offset, cache, etc.)