Fix SingularAssociationAttributeMapping identifyingColumnsTableExpression and inverseIdentifyingColumnsTableExpression values
This commit is contained in:
parent
f3b2a1537b
commit
a4330599c2
|
@ -753,7 +753,6 @@ public class MappingModelCreationHelper {
|
||||||
fkTarget = declaringEntityDescriptor.getIdentifierMapping();
|
fkTarget = declaringEntityDescriptor.getIdentifierMapping();
|
||||||
}
|
}
|
||||||
|
|
||||||
final JdbcServices jdbcServices = creationProcess.getCreationContext().getSessionFactory().getJdbcServices();
|
|
||||||
if ( fkTarget instanceof BasicValuedModelPart ) {
|
if ( fkTarget instanceof BasicValuedModelPart ) {
|
||||||
final String keyColumnExpression;
|
final String keyColumnExpression;
|
||||||
if ( bootValueMapping.isReferenceToPrimaryKey() ) {
|
if ( bootValueMapping.isReferenceToPrimaryKey() ) {
|
||||||
|
|
|
@ -42,7 +42,6 @@ import org.hibernate.sql.ast.tree.from.TableGroup;
|
||||||
import org.hibernate.sql.ast.tree.from.TableGroupJoin;
|
import org.hibernate.sql.ast.tree.from.TableGroupJoin;
|
||||||
import org.hibernate.sql.ast.tree.from.TableGroupJoinProducer;
|
import org.hibernate.sql.ast.tree.from.TableGroupJoinProducer;
|
||||||
import org.hibernate.sql.ast.tree.from.TableReference;
|
import org.hibernate.sql.ast.tree.from.TableReference;
|
||||||
import org.hibernate.sql.ast.tree.predicate.Predicate;
|
|
||||||
import org.hibernate.sql.results.graph.DomainResult;
|
import org.hibernate.sql.results.graph.DomainResult;
|
||||||
import org.hibernate.sql.results.graph.DomainResultCreationState;
|
import org.hibernate.sql.results.graph.DomainResultCreationState;
|
||||||
import org.hibernate.sql.results.graph.Fetch;
|
import org.hibernate.sql.results.graph.Fetch;
|
||||||
|
@ -142,7 +141,7 @@ public class SingularAssociationAttributeMapping extends AbstractSingularAttribu
|
||||||
final String identifyingColumnsTableExpression;
|
final String identifyingColumnsTableExpression;
|
||||||
final String inverseColumnsTableExpression;
|
final String inverseColumnsTableExpression;
|
||||||
final List<String> identifyingColumnsList = new ArrayList<>();
|
final List<String> identifyingColumnsList = new ArrayList<>();
|
||||||
if ( foreignKeyDescriptor.getDirection() == ForeignKeyDirection.TO_PARENT ) {
|
if ( foreignKeyDescriptor.getDirection() == ForeignKeyDirection.FROM_PARENT && !referringPrimaryKey ) {
|
||||||
identifyingColumnsTableExpression = foreignKeyDescriptor.getTargetTableExpression();
|
identifyingColumnsTableExpression = foreignKeyDescriptor.getTargetTableExpression();
|
||||||
inverseColumnsTableExpression = foreignKeyDescriptor.getReferringTableExpression();
|
inverseColumnsTableExpression = foreignKeyDescriptor.getReferringTableExpression();
|
||||||
foreignKeyDescriptor.visitTargetColumns(
|
foreignKeyDescriptor.visitTargetColumns(
|
||||||
|
|
|
@ -13,8 +13,11 @@ import javax.persistence.Table;
|
||||||
|
|
||||||
import org.hibernate.Hibernate;
|
import org.hibernate.Hibernate;
|
||||||
|
|
||||||
import org.hibernate.testing.junit5.SessionFactoryBasedFunctionalTest;
|
import org.hibernate.testing.orm.junit.DomainModel;
|
||||||
import org.hibernate.testing.orm.junit.FailureExpected;
|
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.junit.jupiter.api.AfterEach;
|
import org.junit.jupiter.api.AfterEach;
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
@ -28,20 +31,20 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
/**
|
/**
|
||||||
* @author Chris Cranford
|
* @author Chris Cranford
|
||||||
*/
|
*/
|
||||||
public class EntityWithBidirectionalOneToOneTest extends SessionFactoryBasedFunctionalTest {
|
@DomainModel(
|
||||||
|
annotatedClasses = {
|
||||||
@Override
|
EntityWithBidirectionalOneToOneTest.Parent.class,
|
||||||
protected Class[] getAnnotatedClasses() {
|
EntityWithBidirectionalOneToOneTest.Child.class,
|
||||||
return new Class[] {
|
EntityWithBidirectionalOneToOneTest.Child2.class
|
||||||
Parent.class,
|
}
|
||||||
Child.class,
|
)
|
||||||
Child2.class,
|
@ServiceRegistry
|
||||||
};
|
@SessionFactory(generateStatistics = true)
|
||||||
}
|
public class EntityWithBidirectionalOneToOneTest {
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
public void setUp() {
|
public void setUp(SessionFactoryScope scope) {
|
||||||
inTransaction( session -> {
|
scope.inTransaction( session -> {
|
||||||
Parent parent = new Parent( 1, "Hibernate ORM" );
|
Parent parent = new Parent( 1, "Hibernate ORM" );
|
||||||
Child child = new Child( 2, parent );
|
Child child = new Child( 2, parent );
|
||||||
child.setName( "Acme" );
|
child.setName( "Acme" );
|
||||||
|
@ -54,8 +57,8 @@ public class EntityWithBidirectionalOneToOneTest extends SessionFactoryBasedFunc
|
||||||
}
|
}
|
||||||
|
|
||||||
@AfterEach
|
@AfterEach
|
||||||
public void tearDown() {
|
public void tearDown(SessionFactoryScope scope) {
|
||||||
inTransaction( session -> {
|
scope.inTransaction( session -> {
|
||||||
session.createQuery( "delete from Child2" ).executeUpdate();
|
session.createQuery( "delete from Child2" ).executeUpdate();
|
||||||
session.createQuery( "delete from Parent" ).executeUpdate();
|
session.createQuery( "delete from Parent" ).executeUpdate();
|
||||||
session.createQuery( "delete from Child" ).executeUpdate();
|
session.createQuery( "delete from Child" ).executeUpdate();
|
||||||
|
@ -63,8 +66,8 @@ public class EntityWithBidirectionalOneToOneTest extends SessionFactoryBasedFunc
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetParent() {
|
public void testGetParent(SessionFactoryScope scope) {
|
||||||
inTransaction( session -> {
|
scope.inTransaction( session -> {
|
||||||
final Parent parent = session.get( Parent.class, 1 );
|
final Parent parent = session.get( Parent.class, 1 );
|
||||||
Child child = parent.getOwnedBidirectionalChild();
|
Child child = parent.getOwnedBidirectionalChild();
|
||||||
assertThat( child, notNullValue() );
|
assertThat( child, notNullValue() );
|
||||||
|
@ -89,8 +92,8 @@ public class EntityWithBidirectionalOneToOneTest extends SessionFactoryBasedFunc
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetParent2() {
|
public void testGetParent2(SessionFactoryScope scope) {
|
||||||
inTransaction( session -> {
|
scope.inTransaction( session -> {
|
||||||
Parent parent = new Parent( 4, "Hibernate OGM" );
|
Parent parent = new Parent( 4, "Hibernate OGM" );
|
||||||
Child child = new Child( 5, parent );
|
Child child = new Child( 5, parent );
|
||||||
child.setName( "Acme2" );
|
child.setName( "Acme2" );
|
||||||
|
@ -105,7 +108,7 @@ public class EntityWithBidirectionalOneToOneTest extends SessionFactoryBasedFunc
|
||||||
session.save( child2 );
|
session.save( child2 );
|
||||||
} );
|
} );
|
||||||
|
|
||||||
inTransaction( session -> {
|
scope.inTransaction( session -> {
|
||||||
final Parent parent = session.get( Parent.class, 4 );
|
final Parent parent = session.get( Parent.class, 4 );
|
||||||
Child child = parent.getOwnedBidirectionalChild();
|
Child child = parent.getOwnedBidirectionalChild();
|
||||||
assertThat( child, notNullValue() );
|
assertThat( child, notNullValue() );
|
||||||
|
@ -135,8 +138,8 @@ public class EntityWithBidirectionalOneToOneTest extends SessionFactoryBasedFunc
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetParent3() {
|
public void testGetParent3(SessionFactoryScope scope) {
|
||||||
inTransaction( session -> {
|
scope.inTransaction( session -> {
|
||||||
|
|
||||||
Parent parent = new Parent( 4, "Hibernate Search" );
|
Parent parent = new Parent( 4, "Hibernate Search" );
|
||||||
Child child = new Child( 5, parent );
|
Child child = new Child( 5, parent );
|
||||||
|
@ -156,7 +159,7 @@ public class EntityWithBidirectionalOneToOneTest extends SessionFactoryBasedFunc
|
||||||
session.save( child2 );
|
session.save( child2 );
|
||||||
} );
|
} );
|
||||||
|
|
||||||
inTransaction( session -> {
|
scope.inTransaction( session -> {
|
||||||
final Parent parent = session.get( Parent.class, 4 );
|
final Parent parent = session.get( Parent.class, 4 );
|
||||||
assertThat( parent.getDescription(), equalTo( "Hibernate Search" ) );
|
assertThat( parent.getDescription(), equalTo( "Hibernate Search" ) );
|
||||||
|
|
||||||
|
@ -188,8 +191,8 @@ public class EntityWithBidirectionalOneToOneTest extends SessionFactoryBasedFunc
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetChild() {
|
public void testGetChild(SessionFactoryScope scope) {
|
||||||
inTransaction( session -> {
|
scope.inTransaction( session -> {
|
||||||
final Child child = session.get( Child.class, 2 );
|
final Child child = session.get( Child.class, 2 );
|
||||||
Parent parent = child.getParentMappedByChild();
|
Parent parent = child.getParentMappedByChild();
|
||||||
assertTrue(
|
assertTrue(
|
||||||
|
@ -216,8 +219,8 @@ public class EntityWithBidirectionalOneToOneTest extends SessionFactoryBasedFunc
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testHqlSelectParent() {
|
public void testHqlSelectParent(SessionFactoryScope scope) {
|
||||||
inTransaction(
|
scope.inTransaction(
|
||||||
session -> {
|
session -> {
|
||||||
final Parent parent = session.createQuery(
|
final Parent parent = session.createQuery(
|
||||||
"SELECT p FROM Parent p JOIN p.ownedBidirectionalChild WHERE p.id = :id",
|
"SELECT p FROM Parent p JOIN p.ownedBidirectionalChild WHERE p.id = :id",
|
||||||
|
@ -235,8 +238,8 @@ public class EntityWithBidirectionalOneToOneTest extends SessionFactoryBasedFunc
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@FailureExpected
|
@FailureExpected
|
||||||
public void testHqlSelectChild() {
|
public void testHqlSelectChild(SessionFactoryScope scope) {
|
||||||
inTransaction(
|
scope.inTransaction(
|
||||||
session -> {
|
session -> {
|
||||||
final String queryString = "SELECT c FROM Child c JOIN c.parentMappedByChild d WHERE d.id = :id";
|
final String queryString = "SELECT c FROM Child c JOIN c.parentMappedByChild d WHERE d.id = :id";
|
||||||
final Child child = session.createQuery( queryString, Child.class )
|
final Child child = session.createQuery( queryString, Child.class )
|
||||||
|
|
Loading…
Reference in New Issue