HHH-15964 Adapt failing tests

This commit is contained in:
Réda Housni Alaoui 2023-01-31 21:43:40 +01:00 committed by Steve Ebersole
parent 7902c0d35a
commit 5f3bd06bf8
3 changed files with 69 additions and 55 deletions

View File

@ -45,6 +45,7 @@ import org.hibernate.sql.ast.tree.from.StandardVirtualTableGroup;
import org.hibernate.sql.ast.tree.from.TableGroup; 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.select.SelectStatement; import org.hibernate.sql.ast.tree.select.SelectStatement;
import org.hibernate.sql.results.graph.BiDirectionalFetch;
import org.hibernate.sql.results.graph.DomainResult; import org.hibernate.sql.results.graph.DomainResult;
import org.hibernate.sql.results.graph.Fetch; import org.hibernate.sql.results.graph.Fetch;
import org.hibernate.sql.results.graph.Fetchable; import org.hibernate.sql.results.graph.Fetchable;
@ -54,7 +55,6 @@ import org.hibernate.sql.results.graph.entity.EntityFetch;
import org.hibernate.sql.results.graph.entity.EntityResult; import org.hibernate.sql.results.graph.entity.EntityResult;
import org.hibernate.sql.results.graph.entity.internal.EntityDelayedFetchImpl; import org.hibernate.sql.results.graph.entity.internal.EntityDelayedFetchImpl;
import org.hibernate.sql.results.graph.entity.internal.EntityFetchJoinedImpl; import org.hibernate.sql.results.graph.entity.internal.EntityFetchJoinedImpl;
import org.hibernate.sql.results.graph.internal.ImmutableFetchList;
import org.hibernate.testing.TestForIssue; import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.orm.junit.DomainModel; import org.hibernate.testing.orm.junit.DomainModel;
@ -110,8 +110,20 @@ public class CriteriaEntityGraphTest implements SessionFactoryScopeAware {
assertEmptyJoinedGroup( sqlAst ); assertEmptyJoinedGroup( sqlAst );
// Check the domain-result graph // Check the domain-result graph
assertDomainResult( sqlAst, Cat.class, "owner", Person.class, assertDomainResult( sqlAst, Cat.class,
entityFetch -> assertThat( entityFetch, instanceOf( EntityDelayedFetchImpl.class ) ) fetch -> {
if (graphSemantic == GraphSemantic.LOAD) {
assertThat( fetch, instanceOf( BiDirectionalFetch.class ) );
} else {
assertThat( fetch, instanceOf( EntityFetch.class ) );
final EntityFetch entityFetch = (EntityFetch) fetch;
assertThat( entityFetch.getFetchedMapping().getFetchableName(), is( "owner" ) );
assertThat( entityFetch.getReferencedModePart().getJavaType().getJavaTypeClass(), assignableTo( Person.class ) );
assertThat(entityFetch, instanceOf(EntityDelayedFetchImpl.class));
}
}
); );
} }
); );
@ -131,7 +143,14 @@ public class CriteriaEntityGraphTest implements SessionFactoryScopeAware {
assertEntityValuedJoinedGroup( sqlAst, "owner", Person.class, this::assertPersonHomeAddressJoinedGroup ); assertEntityValuedJoinedGroup( sqlAst, "owner", Person.class, this::assertPersonHomeAddressJoinedGroup );
// Check the domain-result graph // Check the domain-result graph
assertDomainResult( sqlAst, Cat.class, "owner", Person.class, entityFetch -> { assertDomainResult( sqlAst, Cat.class, aFetch -> {
assertThat( aFetch, instanceOf( EntityFetch.class ) );
final EntityFetch entityFetch = (EntityFetch) aFetch;
assertThat( entityFetch.getFetchedMapping().getFetchableName(), is( "owner" ) );
assertThat( entityFetch.getReferencedModePart().getJavaType().getJavaTypeClass(), assignableTo( Person.class ) );
if ( graphSemantic == GraphSemantic.LOAD ) { if ( graphSemantic == GraphSemantic.LOAD ) {
assertThat( entityFetch, instanceOf( EntityFetchJoinedImpl.class ) ); assertThat( entityFetch, instanceOf( EntityFetchJoinedImpl.class ) );
final EntityResult entityResult = ( (EntityFetchJoinedImpl) entityFetch ).getEntityResult(); final EntityResult entityResult = ( (EntityFetchJoinedImpl) entityFetch ).getEntityResult();
@ -175,7 +194,13 @@ public class CriteriaEntityGraphTest implements SessionFactoryScopeAware {
} ); } );
// Check the domain-result graph // Check the domain-result graph
assertDomainResult( sqlAst, Cat.class, "owner", Person.class, entityFetch -> { assertDomainResult( sqlAst, Cat.class, aFetch -> {
assertThat( aFetch, instanceOf( EntityFetch.class ) );
final EntityFetch entityFetch = (EntityFetch) aFetch;
assertThat( entityFetch.getFetchedMapping().getFetchableName(), is( "owner" ) );
assertThat( entityFetch.getReferencedModePart().getJavaType().getJavaTypeClass(), assignableTo( Person.class ) );
assertThat( entityFetch, instanceOf( EntityFetchJoinedImpl.class ) ); assertThat( entityFetch, instanceOf( EntityFetchJoinedImpl.class ) );
final EntityResult ownerEntityResult = ( (EntityFetchJoinedImpl) entityFetch ).getEntityResult(); final EntityResult ownerEntityResult = ( (EntityFetchJoinedImpl) entityFetch ).getEntityResult();
final Map<String, Class<? extends Fetch>> fetchClassByAttributeName = ownerEntityResult.getFetches() final Map<String, Class<? extends Fetch>> fetchClassByAttributeName = ownerEntityResult.getFetches()
@ -260,17 +285,8 @@ public class CriteriaEntityGraphTest implements SessionFactoryScopeAware {
.next() .next()
.getJoinedGroup(); .getJoinedGroup();
assertThat( compositeTableGroup, instanceOf( StandardVirtualTableGroup.class ) ); assertThat( compositeTableGroup, instanceOf( StandardVirtualTableGroup.class ) );
assertThat( compositeTableGroup.getTableGroupJoins(), hasSize( 1 ) ); assertThat( compositeTableGroup.getTableGroupJoins(), isEmpty() );
assertThat( compositeTableGroup.getNestedTableGroupJoins(), isEmpty() ); assertThat( compositeTableGroup.getNestedTableGroupJoins(), isEmpty() );
final TableGroup countryTableGroup = compositeTableGroup.getTableGroupJoins()
.iterator()
.next()
.getJoinedGroup();
assertThat( countryTableGroup.getModelPart().getPartName(), is( "country" ) );
assertThat( countryTableGroup.getTableGroupJoins(), isEmpty() );
assertThat( countryTableGroup.getNestedTableGroupJoins(), isEmpty() );
} }
else { else {
assertThat( tableGroup.getTableGroupJoins(), isEmpty() ); assertThat( tableGroup.getTableGroupJoins(), isEmpty() );
@ -338,9 +354,7 @@ public class CriteriaEntityGraphTest implements SessionFactoryScopeAware {
private void assertDomainResult(SelectStatement sqlAst, private void assertDomainResult(SelectStatement sqlAst,
Class<?> expectedEntityJpaClass, Class<?> expectedEntityJpaClass,
String expectedAttributeName, Consumer<Fetch> fetchConsumer) {
Class<?> expectedAttributeEntityJpaClass,
Consumer<EntityFetch> entityFetchConsumer) {
assertThat( sqlAst.getDomainResultDescriptors(), hasSize( 1 ) ); assertThat( sqlAst.getDomainResultDescriptors(), hasSize( 1 ) );
final DomainResult domainResult = sqlAst.getDomainResultDescriptors().get( 0 ); final DomainResult domainResult = sqlAst.getDomainResultDescriptors().get( 0 );
@ -351,13 +365,7 @@ public class CriteriaEntityGraphTest implements SessionFactoryScopeAware {
assertThat( entityResult.getFetches().size(), is( 1 ) ); assertThat( entityResult.getFetches().size(), is( 1 ) );
final Fetch fetch = entityResult.getFetches().iterator().next(); final Fetch fetch = entityResult.getFetches().iterator().next();
assertThat( fetch, instanceOf( EntityFetch.class ) ); fetchConsumer.accept(fetch);
final EntityFetch entityFetch = (EntityFetch) fetch;
assertThat( entityFetch.getFetchedMapping().getFetchableName(), is( expectedAttributeName ) );
assertThat( entityFetch.getReferencedModePart().getJavaType().getJavaTypeClass(), assignableTo( expectedAttributeEntityJpaClass ) );
entityFetchConsumer.accept( entityFetch );
} }
private <T> SelectStatement buildSqlSelectAst( private <T> SelectStatement buildSqlSelectAst(

View File

@ -43,6 +43,7 @@ import org.hibernate.sql.ast.tree.from.StandardVirtualTableGroup;
import org.hibernate.sql.ast.tree.from.TableGroup; 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.select.SelectStatement; import org.hibernate.sql.ast.tree.select.SelectStatement;
import org.hibernate.sql.results.graph.BiDirectionalFetch;
import org.hibernate.sql.results.graph.DomainResult; import org.hibernate.sql.results.graph.DomainResult;
import org.hibernate.sql.results.graph.Fetch; import org.hibernate.sql.results.graph.Fetch;
import org.hibernate.sql.results.graph.Fetchable; import org.hibernate.sql.results.graph.Fetchable;
@ -107,8 +108,20 @@ public class HqlEntityGraphTest implements SessionFactoryScopeAware {
assertEmptyJoinedGroup( sqlAst ); assertEmptyJoinedGroup( sqlAst );
// Check the domain-result graph // Check the domain-result graph
assertDomainResult( sqlAst, Cat.class, "owner", Person.class, assertDomainResult(sqlAst, Cat.class,
entityFetch -> assertThat( entityFetch, instanceOf( EntityDelayedFetchImpl.class ) ) fetch -> {
if (graphSemantic == GraphSemantic.LOAD) {
assertThat(fetch, instanceOf(BiDirectionalFetch.class));
} else {
assertThat(fetch, instanceOf(EntityFetch.class));
final EntityFetch entityFetch = (EntityFetch) fetch;
assertThat(entityFetch.getFetchedMapping().getFetchableName(), is("owner"));
assertThat(entityFetch.getReferencedModePart().getJavaType().getJavaTypeClass(), assignableTo(Person.class));
assertThat(entityFetch, instanceOf(EntityDelayedFetchImpl.class));
}
}
); );
} }
); );
@ -128,12 +141,18 @@ public class HqlEntityGraphTest implements SessionFactoryScopeAware {
assertEntityValuedJoinedGroup( sqlAst, "owner", Person.class, this::assertPersonHomeAddressJoinedGroup ); assertEntityValuedJoinedGroup( sqlAst, "owner", Person.class, this::assertPersonHomeAddressJoinedGroup );
// Check the domain-result graph // Check the domain-result graph
assertDomainResult( sqlAst, Cat.class, "owner", Person.class, entityFetch -> { assertDomainResult( sqlAst, Cat.class, fetch -> {
assertThat( fetch, instanceOf( EntityFetch.class ) );
final EntityFetch entityFetch = (EntityFetch) fetch;
assertThat( entityFetch.getFetchedMapping().getFetchableName(), is( "owner" ) );
assertThat( entityFetch.getReferencedModePart().getJavaType().getJavaTypeClass(), assignableTo( Person.class ) );
if ( graphSemantic == GraphSemantic.LOAD ) { if ( graphSemantic == GraphSemantic.LOAD ) {
assertThat( entityFetch, instanceOf( EntityFetchJoinedImpl.class ) ); assertThat( entityFetch, instanceOf( EntityFetchJoinedImpl.class ) );
final EntityResult entityResult = ( (EntityFetchJoinedImpl) entityFetch ).getEntityResult(); final EntityResult entityResult = ( (EntityFetchJoinedImpl) entityFetch ).getEntityResult();
final Map<String, Class<? extends Fetch>> fetchClassByAttributeName = entityResult.getFetches().stream().collect( Collectors.toMap( final Map<String, Class<? extends Fetch>> fetchClassByAttributeName = entityResult.getFetches().stream().collect( Collectors.toMap(
fetch -> fetch.getFetchedMapping().getPartName(), aFetch -> aFetch.getFetchedMapping().getPartName(),
Fetch::getClass Fetch::getClass
) ); ) );
final Map<String, Class<? extends Fetch>> expectedFetchClassByAttributeName = new HashMap<>(); final Map<String, Class<? extends Fetch>> expectedFetchClassByAttributeName = new HashMap<>();
@ -172,12 +191,18 @@ public class HqlEntityGraphTest implements SessionFactoryScopeAware {
} ); } );
// Check the domain-result graph // Check the domain-result graph
assertDomainResult( sqlAst, Cat.class, "owner", Person.class, entityFetch -> { assertDomainResult( sqlAst, Cat.class, fetch -> {
assertThat( fetch, instanceOf( EntityFetch.class ) );
final EntityFetch entityFetch = (EntityFetch) fetch;
assertThat( entityFetch.getFetchedMapping().getFetchableName(), is( "owner" ) );
assertThat( entityFetch.getReferencedModePart().getJavaType().getJavaTypeClass(), assignableTo( Person.class ) );
assertThat( entityFetch, instanceOf( EntityFetchJoinedImpl.class ) ); assertThat( entityFetch, instanceOf( EntityFetchJoinedImpl.class ) );
final EntityResult ownerEntityResult = ( (EntityFetchJoinedImpl) entityFetch ).getEntityResult(); final EntityResult ownerEntityResult = ( (EntityFetchJoinedImpl) entityFetch ).getEntityResult();
final Map<String, Class<? extends Fetch>> fetchClassByAttributeName = ownerEntityResult.getFetches() final Map<String, Class<? extends Fetch>> fetchClassByAttributeName = ownerEntityResult.getFetches()
.stream().collect( Collectors.toMap( .stream().collect( Collectors.toMap(
fetch -> fetch.getFetchedMapping().getPartName(), aFetch -> aFetch.getFetchedMapping().getPartName(),
Fetch::getClass Fetch::getClass
) ); ) );
final Map<String, Class<? extends Fetch>> expectedFetchClassByAttributeName = new HashMap<>(); final Map<String, Class<? extends Fetch>> expectedFetchClassByAttributeName = new HashMap<>();
@ -258,17 +283,8 @@ public class HqlEntityGraphTest implements SessionFactoryScopeAware {
.next() .next()
.getJoinedGroup(); .getJoinedGroup();
assertThat( compositeTableGroup, instanceOf( StandardVirtualTableGroup.class ) ); assertThat( compositeTableGroup, instanceOf( StandardVirtualTableGroup.class ) );
assertThat( compositeTableGroup.getTableGroupJoins(), hasSize( 1 ) ); assertThat( compositeTableGroup.getTableGroupJoins(), isEmpty( ) );
assertThat( compositeTableGroup.getNestedTableGroupJoins(), isEmpty() ); assertThat( compositeTableGroup.getNestedTableGroupJoins(), isEmpty() );
final TableGroup countryTableGroup = compositeTableGroup.getTableGroupJoins()
.iterator()
.next()
.getJoinedGroup();
assertThat( countryTableGroup.getModelPart().getPartName(), is( "country" ) );
assertThat( countryTableGroup.getTableGroupJoins(), isEmpty() );
assertThat( countryTableGroup.getNestedTableGroupJoins(), isEmpty() );
} }
else { else {
assertThat( tableGroup.getTableGroupJoins(), isEmpty() ); assertThat( tableGroup.getTableGroupJoins(), isEmpty() );
@ -335,9 +351,7 @@ public class HqlEntityGraphTest implements SessionFactoryScopeAware {
private void assertDomainResult(SelectStatement sqlAst, private void assertDomainResult(SelectStatement sqlAst,
Class<?> expectedEntityJpaClass, Class<?> expectedEntityJpaClass,
String expectedAttributeName, Consumer<Fetch> fetchConsumer) {
Class<?> expectedAttributeEntityJpaClass,
Consumer<EntityFetch> entityFetchConsumer) {
assertThat( sqlAst.getDomainResultDescriptors(), hasSize( 1 ) ); assertThat( sqlAst.getDomainResultDescriptors(), hasSize( 1 ) );
final DomainResult domainResult = sqlAst.getDomainResultDescriptors().get( 0 ); final DomainResult domainResult = sqlAst.getDomainResultDescriptors().get( 0 );
@ -348,13 +362,7 @@ public class HqlEntityGraphTest implements SessionFactoryScopeAware {
assertThat( entityResult.getFetches().size(), is( 1 ) ); assertThat( entityResult.getFetches().size(), is( 1 ) );
final Fetch fetch = entityResult.getFetches().iterator().next(); final Fetch fetch = entityResult.getFetches().iterator().next();
assertThat( fetch, instanceOf( EntityFetch.class ) ); fetchConsumer.accept(fetch);
final EntityFetch entityFetch = (EntityFetch) fetch;
assertThat( entityFetch.getFetchedMapping().getFetchableName(), is( expectedAttributeName ) );
assertThat( entityFetch.getReferencedModePart().getJavaType().getJavaTypeClass(), assignableTo( expectedAttributeEntityJpaClass ) );
entityFetchConsumer.accept( entityFetch );
} }
private <T> SelectStatement buildSqlSelectAst( private <T> SelectStatement buildSqlSelectAst(

View File

@ -236,8 +236,7 @@ public class LoadAndFetchGraphTest extends BaseEntityManagerFunctionalTestCase {
// depending on the mapping. // depending on the mapping.
assertTrue( Hibernate.isInitialized( cEntity.getEagerC() ) ); assertTrue( Hibernate.isInitialized( cEntity.getEagerC() ) );
// 1 because contrary to 5.x we fetch the eager C along with the main query assertEquals( 2L, statistics.getPrepareStatementCount() );
assertEquals( 1L, statistics.getPrepareStatementCount() );
} ); } );
} }
@ -340,8 +339,7 @@ public class LoadAndFetchGraphTest extends BaseEntityManagerFunctionalTestCase {
assertTrue( Hibernate.isInitialized( cEntity.getEagerC() ) ); assertTrue( Hibernate.isInitialized( cEntity.getEagerC() ) );
} }
// 1 because contrary to 5.x we fetch the eager C along with the main query assertEquals( 3L, statistics.getPrepareStatementCount() );
assertEquals( 1L, statistics.getPrepareStatementCount() );
} ); } );
} }