This is an automated email from the ASF dual-hosted git repository.

borinquenkid pushed a commit to branch 8.0.x-hibernate7
in repository https://gitbox.apache.org/repos/asf/grails-core.git

commit 52c5beac73522689321e524e7cf5d8803e5fd63b
Author: Walter B Duque de Estrada <[email protected]>
AuthorDate: Fri Jan 30 11:05:36 2026 -0600

    progress
---
 .../cfg/domainbinding/IdentityBinder.java          |  3 +
 .../cfg/domainbinding/SimpleIdBinder.java          |  3 -
 .../cfg/domainbinding/IdentityBinderSpec.groovy    | 85 ++++++++++++++--------
 3 files changed, 58 insertions(+), 33 deletions(-)

diff --git 
a/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/IdentityBinder.java
 
b/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/IdentityBinder.java
index cff53074ba..8afcb74cf3 100644
--- 
a/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/IdentityBinder.java
+++ 
b/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/IdentityBinder.java
@@ -60,6 +60,9 @@ public class IdentityBinder {
                         identifierProp = namedIdentityProp;
                     }
                 }
+                if (identity.getName() == null) {
+                    identity.setName(root.getEntityName());
+                }
                 simpleIdBinder.bindSimpleId(identifierProp, root, identity);
             }
         } else {
diff --git 
a/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/SimpleIdBinder.java
 
b/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/SimpleIdBinder.java
index 45f2cb4202..f3960c09ec 100644
--- 
a/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/SimpleIdBinder.java
+++ 
b/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/SimpleIdBinder.java
@@ -57,9 +57,6 @@ public class SimpleIdBinder {
         // create the id value
 
         BasicValueIdCreator idCreator = this.basicValueIdCreator != null ? 
this.basicValueIdCreator : new BasicValueIdCreator(metadataBuildingContext, 
jdbcEnvironment, domainClass, entity);
-        if (mappedId != null && mappedId.getName() == null) {
-            mappedId.setName(entity.getEntityName());
-        }
         BasicValue id = idCreator.getBasicValueId(mappedId, useSequence);
 
         Property idProperty  = new Property();
diff --git 
a/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/IdentityBinderSpec.groovy
 
b/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/IdentityBinderSpec.groovy
index 717e8e846f..132e48d8ae 100644
--- 
a/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/IdentityBinderSpec.groovy
+++ 
b/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/cfg/domainbinding/IdentityBinderSpec.groovy
@@ -7,23 +7,27 @@ import org.grails.orm.hibernate.cfg.Identity
 import org.grails.orm.hibernate.cfg.Mapping
 import org.hibernate.boot.spi.InFlightMetadataCollector
 import org.hibernate.mapping.RootClass
-import spock.lang.Specification
+import grails.gorm.specs.HibernateGormDatastoreSpec
 import spock.lang.Subject
 
-class IdentityBinderSpec extends Specification {
+class IdentityBinderSpec extends HibernateGormDatastoreSpec {
 
     def simpleIdBinder = Mock(SimpleIdBinder)
     def compositeIdBinder = Mock(CompositeIdBinder)
 
     @Subject
-    IdentityBinder binder = new IdentityBinder(simpleIdBinder, 
compositeIdBinder)
+    IdentityBinder binder
+
+    def setup() {
+        binder = new IdentityBinder(simpleIdBinder, compositeIdBinder)
+    }
 
     def "should delegate to simpleIdBinder when mapping is null and 
domainClass has simple identity"() {
         given:
-        def domainClass = GroovyMock(GrailsHibernatePersistentEntity)
-        def root = GroovyMock(RootClass)
-        def mappings = GroovyMock(InFlightMetadataCollector)
-        def identifierProp = GroovyMock(PersistentProperty)
+        def domainClass = Mock(GrailsHibernatePersistentEntity)
+        def root = new 
RootClass(getGrailsDomainBinder().getMetadataBuildingContext())
+        def mappings = Mock(InFlightMetadataCollector)
+        def identifierProp = Mock(PersistentProperty)
         domainClass.getIdentity() >> identifierProp
         domainClass.getCompositeIdentity() >> null
 
@@ -36,10 +40,10 @@ class IdentityBinderSpec extends Specification {
 
     def "should delegate to compositeIdBinder when mapping is null and 
domainClass has composite identity"() {
         given:
-        def domainClass = GroovyMock(GrailsHibernatePersistentEntity)
-        def root = GroovyMock(RootClass)
-        def mappings = GroovyMock(InFlightMetadataCollector)
-        def compositeProps = [GroovyMock(PersistentProperty)] as 
PersistentProperty[]
+        def domainClass = Mock(GrailsHibernatePersistentEntity)
+        def root = new 
RootClass(getGrailsDomainBinder().getMetadataBuildingContext())
+        def mappings = Mock(InFlightMetadataCollector)
+        def compositeProps = [Mock(PersistentProperty)] as PersistentProperty[]
         domainClass.getCompositeIdentity() >> compositeProps
 
         when:
@@ -51,11 +55,11 @@ class IdentityBinderSpec extends Specification {
 
     def "should delegate to compositeIdBinder when mapping specifies composite 
identity"() {
         given:
-        def domainClass = GroovyMock(GrailsHibernatePersistentEntity)
-        def root = GroovyMock(RootClass)
-        def mappings = GroovyMock(InFlightMetadataCollector)
-        def gormMapping = GroovyMock(Mapping)
-        def compositeIdentity = GroovyMock(CompositeIdentity)
+        def domainClass = Mock(GrailsHibernatePersistentEntity)
+        def root = new 
RootClass(getGrailsDomainBinder().getMetadataBuildingContext())
+        def mappings = Mock(InFlightMetadataCollector)
+        def gormMapping = Mock(Mapping)
+        def compositeIdentity = Mock(CompositeIdentity)
         gormMapping.getIdentity() >> compositeIdentity
 
         when:
@@ -67,13 +71,13 @@ class IdentityBinderSpec extends Specification {
 
     def "should delegate to simpleIdBinder when mapping specifies simple 
identity"() {
         given:
-        def domainClass = GroovyMock(GrailsHibernatePersistentEntity)
-        def root = GroovyMock(RootClass)
-        def mappings = GroovyMock(InFlightMetadataCollector)
-        def gormMapping = GroovyMock(Mapping)
+        def domainClass = Mock(GrailsHibernatePersistentEntity)
+        def root = new 
RootClass(getGrailsDomainBinder().getMetadataBuildingContext())
+        def mappings = Mock(InFlightMetadataCollector)
+        def gormMapping = Mock(Mapping)
         def identity = new Identity(name: "foo")
         gormMapping.getIdentity() >> identity
-        def identifierProp = GroovyMock(PersistentProperty)
+        def identifierProp = Mock(PersistentProperty)
         domainClass.getPropertyByName("foo") >> identifierProp
         domainClass.getIdentity() >> identifierProp
         domainClass.getName() >> "MyEntity"
@@ -87,10 +91,10 @@ class IdentityBinderSpec extends Specification {
 
     def "should throw MappingException when mapping specifies a non-existent 
identifier property"() {
         given:
-        def domainClass = GroovyMock(GrailsHibernatePersistentEntity)
-        def root = GroovyMock(RootClass)
-        def mappings = GroovyMock(InFlightMetadataCollector)
-        def gormMapping = GroovyMock(Mapping)
+        def domainClass = Mock(GrailsHibernatePersistentEntity)
+        def root = new 
RootClass(getGrailsDomainBinder().getMetadataBuildingContext())
+        def mappings = Mock(InFlightMetadataCollector)
+        def gormMapping = Mock(Mapping)
         def identity = new Identity(name: "nonExistent")
         gormMapping.getIdentity() >> identity
         domainClass.getName() >> "MyEntity"
@@ -105,13 +109,13 @@ class IdentityBinderSpec extends Specification {
 
     def "should not lookup property by name if identity name matches domain 
class name"() {
         given:
-        def domainClass = GroovyMock(GrailsHibernatePersistentEntity)
-        def root = GroovyMock(RootClass)
-        def mappings = GroovyMock(InFlightMetadataCollector)
-        def gormMapping = GroovyMock(Mapping)
+        def domainClass = Mock(GrailsHibernatePersistentEntity)
+        def root = new 
RootClass(getGrailsDomainBinder().getMetadataBuildingContext())
+        def mappings = Mock(InFlightMetadataCollector)
+        def gormMapping = Mock(Mapping)
         def identity = new Identity(name: "MyEntity")
         gormMapping.getIdentity() >> identity
-        def identifierProp = GroovyMock(PersistentProperty)
+        def identifierProp = Mock(PersistentProperty)
         domainClass.getIdentity() >> identifierProp
         domainClass.getName() >> "MyEntity"
 
@@ -122,4 +126,25 @@ class IdentityBinderSpec extends Specification {
         0 * domainClass.getPropertyByName(_)
         1 * simpleIdBinder.bindSimpleId(identifierProp, root, identity)
     }
+
+    def "should set entity name on identity if it is null"() {
+        given:
+        def domainClass = Mock(GrailsHibernatePersistentEntity)
+        def root = new 
RootClass(getGrailsDomainBinder().getMetadataBuildingContext())
+        root.setEntityName("MyEntity")
+        def mappings = Mock(InFlightMetadataCollector)
+        def gormMapping = Mock(Mapping)
+        def identity = new Identity()
+        gormMapping.getIdentity() >> identity
+        def identifierProp = Mock(PersistentProperty)
+        domainClass.getIdentity() >> identifierProp
+        domainClass.getName() >> "MyEntity"
+
+        when:
+        binder.bindIdentity(domainClass, root, mappings, gormMapping, 
"sessionFactory")
+
+        then:
+        identity.getName() == "MyEntity"
+        1 * simpleIdBinder.bindSimpleId(identifierProp, root, identity)
+    }
 }

Reply via email to