HHH-17460 - Ongoing JPA 32 work

This commit is contained in:
Steve Ebersole 2024-03-26 17:19:18 -05:00
parent 17c6b731a4
commit cda6b2c2a6
3 changed files with 61 additions and 42 deletions

View File

@ -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 );

View File

@ -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<Column> 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." );
}
}
}

View File

@ -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<Column> 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" };
}
}