Search in sources :

Example 1 with CardField

use of org.hibernate.test.annotations.cid.keymanytoone.CardField in project hibernate-orm by hibernate.

the class LoadPlanStructureAssertionTest method testEncapsulatedCompositeIdWithFetches1.

@Test
public void testEncapsulatedCompositeIdWithFetches1() {
    Configuration cfg = new Configuration();
    cfg.addAnnotatedClass(Card.class);
    cfg.addAnnotatedClass(CardField.class);
    cfg.addAnnotatedClass(Key.class);
    cfg.addAnnotatedClass(PrimaryKey.class);
    SessionFactoryImplementor sf = (SessionFactoryImplementor) cfg.buildSessionFactory();
    try {
        final OuterJoinLoadable cardFieldPersister = (OuterJoinLoadable) sf.getClassMetadata(CardField.class);
        doCompare(sf, cardFieldPersister);
        final LoadPlan loadPlan = LoadPlanStructureAssertionHelper.INSTANCE.buildLoadPlan(sf, cardFieldPersister);
        assertEquals(LoadPlan.Disposition.ENTITY_LOADER, loadPlan.getDisposition());
        assertEquals(1, loadPlan.getReturns().size());
        final EntityReturn cardFieldReturn = assertTyping(EntityReturn.class, loadPlan.getReturns().get(0));
        assertEquals(0, cardFieldReturn.getFetches().length);
        // CardField defines a composite pk with 2 many-to-ones : Card and Key (the id description acts as the composite);
        // because it is an @EmbeddedId, the ID provided by the application is used "as is"
        // and fetches are not included in the load plan.
        assertFalse(cardFieldReturn.getIdentifierDescription().hasFetches());
    // we need the readers ordered in a certain manner.  Here specifically: Fetch(Card), Fetch(Key), Return(CardField)
    // 
    // additionally, we need Fetch(Card) and Fetch(Key) to be hydrated/semi-resolved before attempting to
    // resolve the EntityKey for Return(CardField)
    // 
    // together those sound like argument enough to continue keeping readers for "identifier fetches" as part of
    // a special "identifier reader".  generated aliases could help here too to remove cyclic-ness from the graph.
    // but at any rate, we need to know still when this becomes circularity
    } finally {
        sf.close();
    }
}
Also used : OuterJoinLoadable(org.hibernate.persister.entity.OuterJoinLoadable) Configuration(org.hibernate.cfg.Configuration) LoadPlan(org.hibernate.loader.plan.spi.LoadPlan) SessionFactoryImplementor(org.hibernate.engine.spi.SessionFactoryImplementor) CardField(org.hibernate.test.annotations.cid.keymanytoone.CardField) EntityReturn(org.hibernate.loader.plan.spi.EntityReturn) Test(org.junit.Test) EncapsulatedCompositeIdResultSetProcessorTest(org.hibernate.test.loadplans.process.EncapsulatedCompositeIdResultSetProcessorTest)

Aggregations

Configuration (org.hibernate.cfg.Configuration)1 SessionFactoryImplementor (org.hibernate.engine.spi.SessionFactoryImplementor)1 EntityReturn (org.hibernate.loader.plan.spi.EntityReturn)1 LoadPlan (org.hibernate.loader.plan.spi.LoadPlan)1 OuterJoinLoadable (org.hibernate.persister.entity.OuterJoinLoadable)1 CardField (org.hibernate.test.annotations.cid.keymanytoone.CardField)1 EncapsulatedCompositeIdResultSetProcessorTest (org.hibernate.test.loadplans.process.EncapsulatedCompositeIdResultSetProcessorTest)1 Test (org.junit.Test)1