From 4d0422fe05427f08dd9448c1f71e2225ffce521c Mon Sep 17 00:00:00 2001 From: Steve Ebersole Date: Tue, 4 Jun 2024 07:24:15 -0500 Subject: [PATCH] HHH-18060 - HbXmlTransformer work non-aggregated composite id --- .../xml/internal/XmlAnnotationHelper.java | 2 +- ...mpositeIdentifierOnAbstractClassTests.java | 59 +++++++++++++++++++ .../orm/test/boot/models/hbm/ecid/Login.java | 49 +++++++++++++++ .../ecid/StandardNonAggregatedIdTests.java | 40 +++++++++++++ .../models/hbm/ecid/standard-ecid.hbm.xml | 22 +++++++ 5 files changed, 171 insertions(+), 1 deletion(-) create mode 100644 hibernate-core/src/test/java/org/hibernate/orm/test/boot/models/hbm/ecid/EmbeddedCompositeIdentifierOnAbstractClassTests.java create mode 100644 hibernate-core/src/test/java/org/hibernate/orm/test/boot/models/hbm/ecid/Login.java create mode 100644 hibernate-core/src/test/java/org/hibernate/orm/test/boot/models/hbm/ecid/StandardNonAggregatedIdTests.java create mode 100644 hibernate-core/src/test/resources/mappings/models/hbm/ecid/standard-ecid.hbm.xml diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/xml/internal/XmlAnnotationHelper.java b/hibernate-core/src/main/java/org/hibernate/boot/models/xml/internal/XmlAnnotationHelper.java index becab3287d..4a1c7313cb 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/models/xml/internal/XmlAnnotationHelper.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/xml/internal/XmlAnnotationHelper.java @@ -1146,7 +1146,7 @@ public class XmlAnnotationHelper { JaxbIdClassImpl jaxbIdClass, MutableClassDetails target, XmlDocumentContext xmlDocumentContext) { - if ( jaxbIdClass == null ) { + if ( jaxbIdClass == null || StringHelper.isEmpty( jaxbIdClass.getClazz() ) ) { return; } diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/boot/models/hbm/ecid/EmbeddedCompositeIdentifierOnAbstractClassTests.java b/hibernate-core/src/test/java/org/hibernate/orm/test/boot/models/hbm/ecid/EmbeddedCompositeIdentifierOnAbstractClassTests.java new file mode 100644 index 0000000000..27ea93f37e --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/boot/models/hbm/ecid/EmbeddedCompositeIdentifierOnAbstractClassTests.java @@ -0,0 +1,59 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.orm.test.boot.models.hbm.ecid; + +import org.hibernate.cfg.MappingSettings; +import org.hibernate.orm.test.abstractembeddedcomponents.cid.AbstractCompositeIdTest; +import org.hibernate.orm.test.abstractembeddedcomponents.cid.MyInterfaceImpl; + +import org.hibernate.testing.orm.junit.DomainModel; +import org.hibernate.testing.orm.junit.FailureExpected; +import org.hibernate.testing.orm.junit.ServiceRegistry; +import org.hibernate.testing.orm.junit.SessionFactory; +import org.hibernate.testing.orm.junit.SessionFactoryScope; +import org.hibernate.testing.orm.junit.Setting; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Test; + +/** + * @see AbstractCompositeIdTest + * + * @author Steve Ebersole + */ +@SuppressWarnings("JUnitMalformedDeclaration") +@ServiceRegistry(settings = @Setting(name= MappingSettings.TRANSFORM_HBM_XML, value="true")) +@DomainModel( xmlMappings = "org/hibernate/orm/test/abstractembeddedcomponents/cid/Mappings.hbm.xml" ) +@SessionFactory +@FailureExpected +public class EmbeddedCompositeIdentifierOnAbstractClassTests { + + @Test + public void testTransformedHbmXml(SessionFactoryScope scope) { + MyInterfaceImpl myInterface = new MyInterfaceImpl(); + myInterface.setKey1( "key1" ); + myInterface.setKey2( "key2" ); + myInterface.setName( "test" ); + + scope.inTransaction( + session -> { + // test persistence + session.persist( myInterface ); + session.flush(); + + // test loading + session.createQuery( "from MyInterface" ).list(); + } + ); + } + + @AfterEach + void dropTestData(SessionFactoryScope scope) { + scope.inTransaction( (session) -> { + session.createMutationQuery( "delete MyInterface" ).executeUpdate(); + } ); + } +} diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/boot/models/hbm/ecid/Login.java b/hibernate-core/src/test/java/org/hibernate/orm/test/boot/models/hbm/ecid/Login.java new file mode 100644 index 0000000000..f9ae5e0a1f --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/boot/models/hbm/ecid/Login.java @@ -0,0 +1,49 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.orm.test.boot.models.hbm.ecid; + +/** + * @author Steve Ebersole + */ +public class Login { + private String system; + private String username; + private String email; + + public Login() { + } + + public Login(String system, String username, String email) { + this.system = system; + this.username = username; + this.email = email; + } + + public String getSystem() { + return system; + } + + public void setSystem(String system) { + this.system = system; + } + + public String getUsername() { + return username; + } + + public void setUsername(String username) { + this.username = username; + } + + public String getEmail() { + return email; + } + + public void setEmail(String email) { + this.email = email; + } +} diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/boot/models/hbm/ecid/StandardNonAggregatedIdTests.java b/hibernate-core/src/test/java/org/hibernate/orm/test/boot/models/hbm/ecid/StandardNonAggregatedIdTests.java new file mode 100644 index 0000000000..d317670f23 --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/boot/models/hbm/ecid/StandardNonAggregatedIdTests.java @@ -0,0 +1,40 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.orm.test.boot.models.hbm.ecid; + +import java.util.List; + +import org.hibernate.cfg.MappingSettings; + +import org.hibernate.testing.orm.junit.DomainModel; +import org.hibernate.testing.orm.junit.ServiceRegistry; +import org.hibernate.testing.orm.junit.SessionFactory; +import org.hibernate.testing.orm.junit.SessionFactoryScope; +import org.hibernate.testing.orm.junit.Setting; +import org.junit.jupiter.api.Test; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Steve Ebersole + */ +@SuppressWarnings("JUnitMalformedDeclaration") +@ServiceRegistry(settings = @Setting(name= MappingSettings.TRANSFORM_HBM_XML, value="true")) +@DomainModel(xmlMappings = "mappings/models/hbm/ecid/standard-ecid.hbm.xml") +@SessionFactory +public class StandardNonAggregatedIdTests { + @Test + void simpleTest(SessionFactoryScope scope) { + final Login login = new Login( "prod", "john", "john@doe.com" ); + scope.inTransaction( (session) -> session.persist( login ) ); + + scope.inTransaction( (session) -> { + final List logins = session.createSelectionQuery( "from Login", Login.class ).list(); + assertThat( logins ).hasSize( 1 ); + } ); + } +} diff --git a/hibernate-core/src/test/resources/mappings/models/hbm/ecid/standard-ecid.hbm.xml b/hibernate-core/src/test/resources/mappings/models/hbm/ecid/standard-ecid.hbm.xml new file mode 100644 index 0000000000..eb90184b63 --- /dev/null +++ b/hibernate-core/src/test/resources/mappings/models/hbm/ecid/standard-ecid.hbm.xml @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + +