Search in sources :

Example 16 with OuterJoinLoadable

use of org.hibernate.persister.entity.OuterJoinLoadable in project hibernate-orm by hibernate.

the class NoProxyFetchStrategyHelperTest method determineAssociationType.

private AssociationType determineAssociationType(Class<?> entityClass, String path) {
    OuterJoinLoadable entityPersister = (OuterJoinLoadable) sessionFactory().getEntityPersister(entityClass.getName());
    int index = ((UniqueKeyLoadable) entityPersister).getPropertyIndex(path);
    return (AssociationType) entityPersister.getSubclassPropertyType(index);
}
Also used : OuterJoinLoadable(org.hibernate.persister.entity.OuterJoinLoadable) AssociationType(org.hibernate.type.AssociationType) UniqueKeyLoadable(org.hibernate.persister.entity.UniqueKeyLoadable)

Example 17 with OuterJoinLoadable

use of org.hibernate.persister.entity.OuterJoinLoadable 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();
    }
}
Also used : EntityFetch(org.hibernate.loader.plan.spi.EntityFetch) OuterJoinLoadable(org.hibernate.persister.entity.OuterJoinLoadable) CollectionAttributeFetch(org.hibernate.loader.plan.spi.CollectionAttributeFetch) CollectionFetchableElementEntityGraph(org.hibernate.loader.plan.build.internal.returns.CollectionFetchableElementEntityGraph) FetchSource(org.hibernate.loader.plan.spi.FetchSource) Configuration(org.hibernate.cfg.Configuration) LoadPlan(org.hibernate.loader.plan.spi.LoadPlan) SessionFactoryImplementor(org.hibernate.engine.spi.SessionFactoryImplementor) BidirectionalEntityReference(org.hibernate.loader.plan.spi.BidirectionalEntityReference) Key(org.hibernate.test.annotations.cid.keymanytoone.Key) PrimaryKey(org.hibernate.test.annotations.cid.keymanytoone.PrimaryKey) Card(org.hibernate.test.annotations.cid.keymanytoone.Card) EntityReturn(org.hibernate.loader.plan.spi.EntityReturn) Test(org.junit.Test) EncapsulatedCompositeIdResultSetProcessorTest(org.hibernate.test.loadplans.process.EncapsulatedCompositeIdResultSetProcessorTest)

Example 18 with OuterJoinLoadable

use of org.hibernate.persister.entity.OuterJoinLoadable in project hibernate-orm by hibernate.

the class SubqueryExpression method toSqlString.

@Override
public String toSqlString(Criteria criteria, CriteriaQuery criteriaQuery) throws HibernateException {
    final StringBuilder buf = new StringBuilder(toLeftSqlString(criteria, criteriaQuery));
    if (op != null) {
        buf.append(' ').append(op).append(' ');
    }
    if (quantifier != null) {
        buf.append(quantifier).append(' ');
    }
    final SessionFactoryImplementor factory = criteriaQuery.getFactory();
    final OuterJoinLoadable persister = (OuterJoinLoadable) factory.getMetamodel().entityPersister(criteriaImpl.getEntityOrClassName());
    createAndSetInnerQuery(criteriaQuery, factory);
    criteriaImpl.setSession(deriveRootSession(criteria));
    final CriteriaJoinWalker walker = new CriteriaJoinWalker(persister, innerQuery, factory, criteriaImpl, criteriaImpl.getEntityOrClassName(), criteriaImpl.getSession().getLoadQueryInfluencers(), innerQuery.getRootSQLALias());
    return buf.append('(').append(walker.getSQLString()).append(')').toString();
}
Also used : OuterJoinLoadable(org.hibernate.persister.entity.OuterJoinLoadable) SessionFactoryImplementor(org.hibernate.engine.spi.SessionFactoryImplementor) CriteriaJoinWalker(org.hibernate.loader.criteria.CriteriaJoinWalker)

Example 19 with OuterJoinLoadable

use of org.hibernate.persister.entity.OuterJoinLoadable in project hibernate-orm by hibernate.

the class JoinHelper method getRHSColumnNames.

/**
 * Get the columns of the associated table which are to be used in the join
 *
 * @param type The type
 * @param factory The SessionFactory
 *
 * @return The columns for the right-hand-side of the join
 */
public static String[] getRHSColumnNames(AssociationType type, SessionFactoryImplementor factory) {
    final String uniqueKeyPropertyName = type.getRHSUniqueKeyPropertyName();
    final Joinable joinable = type.getAssociatedJoinable(factory);
    if (uniqueKeyPropertyName == null) {
        return joinable.getKeyColumnNames();
    } else {
        return ((OuterJoinLoadable) joinable).getPropertyColumnNames(uniqueKeyPropertyName);
    }
}
Also used : OuterJoinLoadable(org.hibernate.persister.entity.OuterJoinLoadable) Joinable(org.hibernate.persister.entity.Joinable)

Example 20 with OuterJoinLoadable

use of org.hibernate.persister.entity.OuterJoinLoadable 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

OuterJoinLoadable (org.hibernate.persister.entity.OuterJoinLoadable)22 Joinable (org.hibernate.persister.entity.Joinable)6 UniqueKeyLoadable (org.hibernate.persister.entity.UniqueKeyLoadable)6 AssociationType (org.hibernate.type.AssociationType)5 QueryableCollection (org.hibernate.persister.collection.QueryableCollection)4 SessionFactoryImplementor (org.hibernate.engine.spi.SessionFactoryImplementor)3 Configuration (org.hibernate.cfg.Configuration)2 EntityReturn (org.hibernate.loader.plan.spi.EntityReturn)2 LoadPlan (org.hibernate.loader.plan.spi.LoadPlan)2 AssociationKey (org.hibernate.persister.walking.spi.AssociationKey)2 EncapsulatedCompositeIdResultSetProcessorTest (org.hibernate.test.loadplans.process.EncapsulatedCompositeIdResultSetProcessorTest)2 Test (org.junit.Test)2 Iterator (java.util.Iterator)1 Dialect (org.hibernate.dialect.Dialect)1 FetchStrategy (org.hibernate.engine.FetchStrategy)1 FetchStyle (org.hibernate.engine.FetchStyle)1 Fetch (org.hibernate.engine.profile.Fetch)1 FetchProfile (org.hibernate.engine.profile.FetchProfile)1 CriteriaJoinWalker (org.hibernate.loader.criteria.CriteriaJoinWalker)1 CollectionFetchableElementEntityGraph (org.hibernate.loader.plan.build.internal.returns.CollectionFetchableElementEntityGraph)1