From cda6b2c2a6d8f12b63013f107d23253b7e775116 Mon Sep 17 00:00:00 2001 From: Steve Ebersole Date: Tue, 26 Mar 2024 17:19:18 -0500 Subject: [PATCH] HHH-17460 - Ongoing JPA 32 work --- .../attr/OneToOneAttributeProcessing.java | 2 + .../onetoone/OneToOneInXmlTests.java | 51 +++++++++++++++++++ .../annotations/onetoone/OneToOneTest.java | 50 +++--------------- 3 files changed, 61 insertions(+), 42 deletions(-) create mode 100644 hibernate-core/src/test/java/org/hibernate/orm/test/annotations/onetoone/OneToOneInXmlTests.java diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/xml/internal/attr/OneToOneAttributeProcessing.java b/hibernate-core/src/main/java/org/hibernate/boot/models/xml/internal/attr/OneToOneAttributeProcessing.java index 0f5ee93552..e92926dce0 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/models/xml/internal/attr/OneToOneAttributeProcessing.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/xml/internal/attr/OneToOneAttributeProcessing.java @@ -50,6 +50,8 @@ public class OneToOneAttributeProcessing { xmlDocumentContext ); + XmlAnnotationHelper.applyJoinTable( jaxbOneToOne.getJoinTable(), memberDetails, xmlDocumentContext ); + applyAttributeBasics( jaxbOneToOne, memberDetails, oneToOneAnn, accessType, xmlDocumentContext ); applyTarget( memberDetails, jaxbOneToOne, oneToOneAnn, xmlDocumentContext ); applyCascading( jaxbOneToOne.getCascade(), memberDetails, xmlDocumentContext ); diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/onetoone/OneToOneInXmlTests.java b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/onetoone/OneToOneInXmlTests.java new file mode 100644 index 0000000000..0d89c44d0c --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/onetoone/OneToOneInXmlTests.java @@ -0,0 +1,51 @@ +/* + * 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.annotations.onetoone; + +import java.util.Iterator; + +import org.hibernate.mapping.Column; +import org.hibernate.mapping.PersistentClass; +import org.hibernate.mapping.Table; + +import org.hibernate.testing.orm.junit.DomainModel; +import org.hibernate.testing.orm.junit.DomainModelScope; +import org.hibernate.testing.orm.junit.JiraKey; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.fail; + +/** + * @author Steve Ebersole + */ +public class OneToOneInXmlTests { + + @Test + @JiraKey( "HHH-4606" ) + @DomainModel( xmlMappings = "org/hibernate/orm/test/annotations/onetoone/orm.xml" ) + @SuppressWarnings("JUnitMalformedDeclaration") + public void testJoinColumnConfiguredInXml(DomainModelScope scope) { + final PersistentClass pc = scope.getDomainModel().getEntityBinding( Son.class.getName() ); + Table table = pc.getJoins().get( 0 ).getTable(); + Iterator columnItr = table.getColumns().iterator(); + boolean fooFound = false; + boolean barFound = false; + while ( columnItr.hasNext() ) { + Column column = columnItr.next(); + if ( column.getName().equals( "foo" ) ) { + fooFound = true; + } + if ( column.getName().equals( "bar" ) ) { + barFound = true; + } + } + + if ( !(fooFound && barFound) ) { + fail( "The mapping defines join columns which could not be found in the metadata." ); + } + } +} diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/onetoone/OneToOneTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/onetoone/OneToOneTest.java index 8770821100..f37f1c6eee 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/onetoone/OneToOneTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/onetoone/OneToOneTest.java @@ -6,40 +6,33 @@ */ package org.hibernate.orm.test.annotations.onetoone; -import java.util.Iterator; import java.util.List; -import jakarta.persistence.criteria.CriteriaBuilder; -import jakarta.persistence.criteria.CriteriaQuery; -import jakarta.persistence.criteria.Root; - -import org.hibernate.query.Query; import org.hibernate.Session; import org.hibernate.Transaction; -import org.hibernate.mapping.Column; -import org.hibernate.mapping.Join; -import org.hibernate.mapping.PersistentClass; -import org.hibernate.mapping.Table; - -import org.hibernate.testing.TestForIssue; -import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase; -import org.hibernate.testing.transaction.TransactionUtil; import org.hibernate.orm.test.annotations.Customer; import org.hibernate.orm.test.annotations.Discount; import org.hibernate.orm.test.annotations.Passport; import org.hibernate.orm.test.annotations.Ticket; +import org.hibernate.query.Query; import org.hibernate.query.criteria.HibernateCriteriaBuilder; import org.hibernate.query.criteria.JpaCriteriaQuery; import org.hibernate.query.criteria.JpaRoot; +import org.hibernate.testing.TestForIssue; +import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase; +import org.hibernate.testing.transaction.TransactionUtil; import org.junit.Test; +import jakarta.persistence.criteria.CriteriaBuilder; +import jakarta.persistence.criteria.CriteriaQuery; +import jakarta.persistence.criteria.Root; + import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.notNullValue; import static org.hamcrest.MatcherAssert.assertThat; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; /** * @author Emmanuel Bernard @@ -304,28 +297,6 @@ public class OneToOneTest extends BaseNonConfigCoreFunctionalTestCase { } ); } - @Test - @TestForIssue( jiraKey = "HHH-4606" ) - public void testJoinColumnConfiguredInXml() { - PersistentClass pc = metadata().getEntityBinding( Son.class.getName() ); - Table table = pc.getJoins().get( 0 ).getTable(); - Iterator columnIter = table.getColumns().iterator(); - boolean fooFound = false; - boolean barFound = false; - while ( columnIter.hasNext() ) { - Column column = columnIter.next(); - if ( column.getName().equals( "foo" ) ) { - fooFound = true; - } - if ( column.getName().equals( "bar" ) ) { - barFound = true; - } - } - assertTrue( - "The mapping defines join columns which could not be found in the metadata.", fooFound && barFound - ); - } - @Test @TestForIssue(jiraKey = "HHH-6723") public void testPkOneToOneSelectStatementDoesNotGenerateExtraJoin() { @@ -473,9 +444,4 @@ public class OneToOneTest extends BaseNonConfigCoreFunctionalTestCase { }; } - @Override - protected String[] getXmlFiles() { - return new String[] { "org/hibernate/orm/test/annotations/onetoone/orm.xml" }; - } - }