use of org.hibernate.loader.plan.spi.EntityFetch in project hibernate-orm by hibernate.
the class LoadPlanBuilderTest method testCascadeBasedBuild.
@Test
public void testCascadeBasedBuild() {
EntityPersister ep = (EntityPersister) sessionFactory().getClassMetadata(Message.class);
CascadeStyleLoadPlanBuildingAssociationVisitationStrategy strategy = new CascadeStyleLoadPlanBuildingAssociationVisitationStrategy(CascadingActions.MERGE, sessionFactory(), LoadQueryInfluencers.NONE, LockMode.NONE);
LoadPlan plan = MetamodelDrivenLoadPlanBuilder.buildRootEntityLoadPlan(strategy, ep);
assertFalse(plan.hasAnyScalarReturns());
assertEquals(1, plan.getReturns().size());
Return rtn = plan.getReturns().get(0);
EntityReturn entityReturn = ExtraAssertions.assertTyping(EntityReturn.class, rtn);
assertNotNull(entityReturn.getFetches());
assertEquals(1, entityReturn.getFetches().length);
Fetch fetch = entityReturn.getFetches()[0];
EntityFetch entityFetch = ExtraAssertions.assertTyping(EntityFetch.class, fetch);
assertNotNull(entityFetch.getFetches());
assertEquals(0, entityFetch.getFetches().length);
LoadPlanTreePrinter.INSTANCE.logTree(plan, new AliasResolutionContextImpl(sessionFactory()));
}
use of org.hibernate.loader.plan.spi.EntityFetch in project hibernate-orm by hibernate.
the class LoadPlanStructureAssertionTest method testEncapsulatedCompositeIdWithFetches2.
@Test
public void testEncapsulatedCompositeIdWithFetches2() {
Configuration cfg = new Configuration();
cfg.addAnnotatedClass(Card.class);
cfg.addAnnotatedClass(CardField.class);
cfg.addAnnotatedClass(Key.class);
cfg.addAnnotatedClass(PrimaryKey.class);
final SessionFactoryImplementor sf = (SessionFactoryImplementor) cfg.buildSessionFactory();
try {
final OuterJoinLoadable cardPersister = (OuterJoinLoadable) sf.getClassMetadata(Card.class);
doCompare(sf, cardPersister);
final LoadPlan cardLoadPlan = LoadPlanStructureAssertionHelper.INSTANCE.buildLoadPlan(sf, cardPersister);
assertEquals(LoadPlan.Disposition.ENTITY_LOADER, cardLoadPlan.getDisposition());
assertEquals(1, cardLoadPlan.getReturns().size());
// Check the root EntityReturn(Card)
final EntityReturn cardReturn = assertTyping(EntityReturn.class, cardLoadPlan.getReturns().get(0));
assertFalse(cardReturn.getIdentifierDescription().hasFetches());
// Card should have one fetch, the fields collection
assertEquals(1, cardReturn.getFetches().length);
final CollectionAttributeFetch fieldsFetch = assertTyping(CollectionAttributeFetch.class, cardReturn.getFetches()[0]);
assertNotNull(fieldsFetch.getElementGraph());
// the Card.fields collection has entity elements of type CardField...
final CollectionFetchableElementEntityGraph cardFieldElementGraph = assertTyping(CollectionFetchableElementEntityGraph.class, fieldsFetch.getElementGraph());
// CardField should have no fetches
assertEquals(0, cardFieldElementGraph.getFetches().length);
// But it should have 1 key-many-to-one fetch for Key (Card is already handled)
assertTrue(cardFieldElementGraph.getIdentifierDescription().hasFetches());
final FetchSource cardFieldElementGraphIdAsFetchSource = assertTyping(FetchSource.class, cardFieldElementGraph.getIdentifierDescription());
assertEquals(1, cardFieldElementGraphIdAsFetchSource.getFetches().length);
assertEquals(1, cardFieldElementGraphIdAsFetchSource.getBidirectionalEntityReferences().length);
BidirectionalEntityReference circularCardFetch = assertTyping(BidirectionalEntityReference.class, cardFieldElementGraphIdAsFetchSource.getBidirectionalEntityReferences()[0]);
assertSame(circularCardFetch.getTargetEntityReference(), cardReturn);
// the fetch above is to the other key-many-to-one for CardField.primaryKey composite: key
EntityFetch keyFetch = assertTyping(EntityFetch.class, cardFieldElementGraphIdAsFetchSource.getFetches()[0]);
assertEquals(Key.class.getName(), keyFetch.getEntityPersister().getEntityName());
} finally {
sf.close();
}
}
Aggregations