Search in sources :

Example 1 with Entity1

use of org.hibernate.jpa.test.metamodel.Entity1 in project hibernate-orm by hibernate.

the class FetchAndJoinTest method testImplicitJoinFromExplicitCollectionJoin.

@Test
public void testImplicitJoinFromExplicitCollectionJoin() {
    EntityManager em = getOrCreateEntityManager();
    em.getTransaction().begin();
    final CriteriaBuilder builder = em.getCriteriaBuilder();
    final CriteriaQuery<Entity1> criteria = builder.createQuery(Entity1.class);
    final Root<Entity1> root = criteria.from(Entity1.class);
    // illegal with fetch join
    final Join<Entity1, Entity2> entity2Join = root.join(Entity1_.entity2, JoinType.INNER);
    // <=== REMOVE
    final Fetch<Entity1, Entity2> entity2Fetch = root.fetch(Entity1_.entity2, JoinType.INNER);
    // <=== REMOVE
    entity2Fetch.fetch(Entity2_.entity3);
    criteria.where(builder.equal(root.get(Entity1_.value), "test"), // illegal with fetch join
    builder.equal(entity2Join.get(Entity2_.value), "test"));
    em.createQuery(criteria).getResultList();
    em.getTransaction().commit();
    em.close();
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) EntityManager(javax.persistence.EntityManager) Entity2(org.hibernate.jpa.test.metamodel.Entity2) Entity1(org.hibernate.jpa.test.metamodel.Entity1) Test(org.junit.Test) AbstractMetamodelSpecificTest(org.hibernate.jpa.test.metamodel.AbstractMetamodelSpecificTest)

Aggregations

EntityManager (javax.persistence.EntityManager)1 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)1 AbstractMetamodelSpecificTest (org.hibernate.jpa.test.metamodel.AbstractMetamodelSpecificTest)1 Entity1 (org.hibernate.jpa.test.metamodel.Entity1)1 Entity2 (org.hibernate.jpa.test.metamodel.Entity2)1 Test (org.junit.Test)1