Search in sources :

Example 16 with SessionFactoryScope

use of org.hibernate.testing.orm.junit.SessionFactoryScope in project hibernate-orm by hibernate.

the class AbstractQueryCacheResultTransformerTest method testAliasToEntityMapMultiProjectionWithNullAliasList.

@Test
public void testAliasToEntityMapMultiProjectionWithNullAliasList(SessionFactoryScope scope) throws Exception {
    CriteriaExecutor criteriaExecutor = new CriteriaExecutor() {

        @Override
        protected JpaCriteriaQuery getCriteria(Session s) {
            CriteriaBuilder builder = s.getCriteriaBuilder();
            JpaCriteriaQuery criteria = (JpaCriteriaQuery) builder.createQuery();
            final JpaRoot<Enrolment> root = criteria.from(Enrolment.class);
            criteria.multiselect(root.get("student").alias("student"), root.get("semester"), root.get("year"), root.get("course").alias("course"));
            criteria.orderBy(builder.asc(root.get("studentNumber")));
            return criteria;
        // return s.createCriteria( Enrolment.class, "e" )
        // .setProjection(
        // Projections.projectionList()
        // .add( Property.forName( "e.student" ), "student" )
        // .add( Property.forName( "e.semester" ) )
        // .add( Property.forName( "e.year" ) )
        // .add( Property.forName( "e.course" ), "course" )
        // )
        // .addOrder( Order.asc( "e.studentNumber") )
        // .setResultTransformer( Transformers.ALIAS_TO_ENTITY_MAP );
        }
    };
    HqlExecutor hqlExecutor = new HqlExecutor() {

        @Override
        public Query getQuery(Session s) {
            return s.createQuery("select e.student as student, e.semester, e.year, e.course as course from Enrolment e order by e.studentNumber").setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP);
        }
    };
    ResultChecker checker = results -> {
        List resultList = (List) results;
        assertEquals(2, resultList.size());
        Map yogiMap = (Map) resultList.get(0);
        Map shermanMap = (Map) resultList.get(1);
        // TODO: following are initialized for hql and uninitialied for criteria; why?
        // assertFalse( Hibernate.isInitialized( yogiMap.get( "student" ) ) );
        // assertFalse( Hibernate.isInitialized( shermanMap.get( "student" ) ) );
        assertTrue(yogiMap.get("student") instanceof Student);
        assertEquals(yogiExpected.getStudentNumber(), ((Student) yogiMap.get("student")).getStudentNumber());
        assertEquals(shermanExpected.getStudentNumber(), ((Student) shermanMap.get("student")).getStudentNumber());
        assertNull(yogiMap.get("semester"));
        assertNull(yogiMap.get("year"));
        assertEquals(courseExpected, yogiMap.get("course"));
        assertNull(shermanMap.get("semester"));
        assertNull(shermanMap.get("year"));
        assertEquals(courseExpected, shermanMap.get("course"));
    };
    runTest(hqlExecutor, criteriaExecutor, checker, false, scope);
}
Also used : CriteriaBuilder(jakarta.persistence.criteria.CriteriaBuilder) BasicTypeImpl(org.hibernate.type.internal.BasicTypeImpl) ServiceRegistry(org.hibernate.testing.orm.junit.ServiceRegistry) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) JoinType(jakarta.persistence.criteria.JoinType) JpaSelection(org.hibernate.query.criteria.JpaSelection) AvailableSettings(org.hibernate.cfg.AvailableSettings) Assertions.assertNotEquals(org.junit.jupiter.api.Assertions.assertNotEquals) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) Session(org.hibernate.Session) Constructor(java.lang.reflect.Constructor) ArrayList(java.util.ArrayList) HibernateProxy(org.hibernate.proxy.HibernateProxy) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) Map(java.util.Map) Query(org.hibernate.query.Query) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) SessionFactoryImplementor(org.hibernate.engine.spi.SessionFactoryImplementor) Order(jakarta.persistence.criteria.Order) BigIntJdbcType(org.hibernate.type.descriptor.jdbc.BigIntJdbcType) Transformers(org.hibernate.transform.Transformers) Iterator(java.util.Iterator) ListJoin(jakarta.persistence.criteria.ListJoin) ReflectHelper(org.hibernate.internal.util.ReflectHelper) DomainModel(org.hibernate.testing.orm.junit.DomainModel) AliasToBeanConstructorResultTransformer(org.hibernate.transform.AliasToBeanConstructorResultTransformer) Selection(jakarta.persistence.criteria.Selection) CacheMode(org.hibernate.CacheMode) Assertions.assertSame(org.junit.jupiter.api.Assertions.assertSame) JpaCriteriaQuery(org.hibernate.query.criteria.JpaCriteriaQuery) Test(org.junit.jupiter.api.Test) MapJoin(jakarta.persistence.criteria.MapJoin) List(java.util.List) Root(jakarta.persistence.criteria.Root) SessionFactoryScope(org.hibernate.testing.orm.junit.SessionFactoryScope) CriteriaBuilder(jakarta.persistence.criteria.CriteriaBuilder) JpaRoot(org.hibernate.query.criteria.JpaRoot) LongJavaType(org.hibernate.type.descriptor.java.LongJavaType) Setting(org.hibernate.testing.orm.junit.Setting) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) AliasToEntityMapResultTransformer(org.hibernate.transform.AliasToEntityMapResultTransformer) SessionFactory(org.hibernate.testing.orm.junit.SessionFactory) Path(jakarta.persistence.criteria.Path) Hibernate(org.hibernate.Hibernate) ResultTransformer(org.hibernate.transform.ResultTransformer) Type(org.hibernate.type.Type) Join(jakarta.persistence.criteria.Join) ArrayList(java.util.ArrayList) List(java.util.List) JpaCriteriaQuery(org.hibernate.query.criteria.JpaCriteriaQuery) Map(java.util.Map) Session(org.hibernate.Session) Test(org.junit.jupiter.api.Test)

Example 17 with SessionFactoryScope

use of org.hibernate.testing.orm.junit.SessionFactoryScope in project hibernate-orm by hibernate.

the class AbstractQueryCacheResultTransformerTest method testEntityWithJoinedLazyOneToManySingleElementListCriteria.

@Test
public void testEntityWithJoinedLazyOneToManySingleElementListCriteria(SessionFactoryScope scope) throws Exception {
    CriteriaExecutor criteriaExecutorUnaliased = new CriteriaExecutor() {

        @Override
        protected ResultTransformer getResultTransformer() {
            return null;
        }

        @Override
        protected JpaCriteriaQuery getCriteria(Session s) {
            CriteriaBuilder builder = s.getCriteriaBuilder();
            JpaCriteriaQuery<Student> criteria = (JpaCriteriaQuery<Student>) builder.createQuery(Student.class);
            Root<Student> root = criteria.from(Student.class);
            root.fetch("enrolments", JoinType.LEFT);
            criteria.orderBy(builder.asc(root.get("studentNumber")));
            return criteria;
        // return s.createCriteria( Student.class, "s" )
        // .createCriteria( "s.enrolments", Criteria.LEFT_JOIN )
        // .addOrder( Order.asc( "s.studentNumber") );
        }
    };
    // CriteriaExecutor criteriaExecutorAliased1 = new CriteriaExecutor() {
    // protected JpaCriteriaQuery getCriteria(Session s) {
    // //				return s.createCriteria( Student.class, "s" )
    // //						.createCriteria( "s.enrolments", "e", Criteria.LEFT_JOIN )
    // //						.addOrder( Order.asc( "s.studentNumber") );
    // }
    // };
    // CriteriaExecutor criteriaExecutorAliased2 = new CriteriaExecutor() {
    // protected JpaCriteriaQuery getCriteria(Session s) {
    // //				return s.createCriteria( Student.class, "s" )
    // //						.createAlias( "s.enrolments", "e", Criteria.LEFT_JOIN )
    // //						.addOrder( Order.asc( "s.studentNumber") );
    // }
    // };
    ResultChecker checker = results -> {
        List resultList = (List) results;
        assertEquals(2, resultList.size());
        assertEquals(yogiExpected, resultList.get(0));
        assertEquals(shermanExpected, resultList.get(1));
        assertNotNull(((Student) resultList.get(0)).getEnrolments());
        assertNotNull(((Student) resultList.get(1)).getEnrolments());
        if (areDynamicNonLazyAssociationsChecked()) {
            assertTrue(Hibernate.isInitialized(((Student) resultList.get(0)).getEnrolments()));
            assertEquals(yogiExpected.getEnrolments(), ((Student) resultList.get(0)).getEnrolments());
            assertTrue(Hibernate.isInitialized(((Student) resultList.get(1)).getEnrolments()));
            assertEquals(shermanExpected.getEnrolments(), ((Student) resultList.get(1)).getEnrolments());
        }
    };
    runTest(null, criteriaExecutorUnaliased, checker, false, scope);
// runTest(  null, criteriaExecutorAliased1, checker, false );
// runTest(  null, criteriaExecutorAliased2, checker, false );
}
Also used : CriteriaBuilder(jakarta.persistence.criteria.CriteriaBuilder) BasicTypeImpl(org.hibernate.type.internal.BasicTypeImpl) ServiceRegistry(org.hibernate.testing.orm.junit.ServiceRegistry) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) JoinType(jakarta.persistence.criteria.JoinType) JpaSelection(org.hibernate.query.criteria.JpaSelection) AvailableSettings(org.hibernate.cfg.AvailableSettings) Assertions.assertNotEquals(org.junit.jupiter.api.Assertions.assertNotEquals) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) Session(org.hibernate.Session) Constructor(java.lang.reflect.Constructor) ArrayList(java.util.ArrayList) HibernateProxy(org.hibernate.proxy.HibernateProxy) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) Map(java.util.Map) Query(org.hibernate.query.Query) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) SessionFactoryImplementor(org.hibernate.engine.spi.SessionFactoryImplementor) Order(jakarta.persistence.criteria.Order) BigIntJdbcType(org.hibernate.type.descriptor.jdbc.BigIntJdbcType) Transformers(org.hibernate.transform.Transformers) Iterator(java.util.Iterator) ListJoin(jakarta.persistence.criteria.ListJoin) ReflectHelper(org.hibernate.internal.util.ReflectHelper) DomainModel(org.hibernate.testing.orm.junit.DomainModel) AliasToBeanConstructorResultTransformer(org.hibernate.transform.AliasToBeanConstructorResultTransformer) Selection(jakarta.persistence.criteria.Selection) CacheMode(org.hibernate.CacheMode) Assertions.assertSame(org.junit.jupiter.api.Assertions.assertSame) JpaCriteriaQuery(org.hibernate.query.criteria.JpaCriteriaQuery) Test(org.junit.jupiter.api.Test) MapJoin(jakarta.persistence.criteria.MapJoin) List(java.util.List) Root(jakarta.persistence.criteria.Root) SessionFactoryScope(org.hibernate.testing.orm.junit.SessionFactoryScope) CriteriaBuilder(jakarta.persistence.criteria.CriteriaBuilder) JpaRoot(org.hibernate.query.criteria.JpaRoot) LongJavaType(org.hibernate.type.descriptor.java.LongJavaType) Setting(org.hibernate.testing.orm.junit.Setting) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) AliasToEntityMapResultTransformer(org.hibernate.transform.AliasToEntityMapResultTransformer) SessionFactory(org.hibernate.testing.orm.junit.SessionFactory) Path(jakarta.persistence.criteria.Path) Hibernate(org.hibernate.Hibernate) ResultTransformer(org.hibernate.transform.ResultTransformer) Type(org.hibernate.type.Type) Join(jakarta.persistence.criteria.Join) ArrayList(java.util.ArrayList) List(java.util.List) JpaCriteriaQuery(org.hibernate.query.criteria.JpaCriteriaQuery) Session(org.hibernate.Session) Test(org.junit.jupiter.api.Test)

Example 18 with SessionFactoryScope

use of org.hibernate.testing.orm.junit.SessionFactoryScope in project hibernate-orm by hibernate.

the class AbstractQueryCacheResultTransformerTest method testMultiSelectNewListList.

@Test
public void testMultiSelectNewListList(SessionFactoryScope scope) throws Exception {
    CriteriaExecutor criteriaExecutor = new CriteriaExecutor() {

        @Override
        protected ResultTransformer getResultTransformer() {
            return Transformers.TO_LIST;
        }

        @Override
        protected JpaCriteriaQuery getCriteria(Session s) {
            CriteriaBuilder builder = s.getCriteriaBuilder();
            JpaCriteriaQuery criteria = (JpaCriteriaQuery) builder.createQuery();
            Root<Student> root = criteria.from(Student.class);
            criteria.multiselect(root.get("studentNumber").alias("studentNumber"), root.get("name").alias("name"));
            criteria.orderBy(builder.asc(root.get("studentNumber")));
            return criteria;
        // return s.createCriteria( Student.class, "s" )
        // .setProjection(
        // Projections.projectionList()
        // .add( Property.forName( "s.studentNumber" ).as( "studentNumber" ))
        // .add( Property.forName( "s.name" ).as( "name" ) )
        // )
        // .addOrder( Order.asc( "s.studentNumber" ) )
        // .setResultTransformer( Transformers.TO_LIST );
        }
    };
    HqlExecutor hqlExecutor = new HqlExecutor() {

        @Override
        public Query getQuery(Session s) {
            return s.createQuery("select new list(s.studentNumber, s.name) from Student s order by s.studentNumber");
        }
    };
    ResultChecker checker = results -> {
        List resultList = (List) results;
        assertEquals(2, resultList.size());
        List yogiList = (List) resultList.get(0);
        assertEquals(yogiExpected.getStudentNumber(), yogiList.get(0));
        assertEquals(yogiExpected.getName(), yogiList.get(1));
        List shermanList = (List) resultList.get(1);
        assertEquals(shermanExpected.getStudentNumber(), shermanList.get(0));
        assertEquals(shermanExpected.getName(), shermanList.get(1));
    };
    runTest(hqlExecutor, criteriaExecutor, checker, false, scope);
}
Also used : CriteriaBuilder(jakarta.persistence.criteria.CriteriaBuilder) BasicTypeImpl(org.hibernate.type.internal.BasicTypeImpl) ServiceRegistry(org.hibernate.testing.orm.junit.ServiceRegistry) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) JoinType(jakarta.persistence.criteria.JoinType) JpaSelection(org.hibernate.query.criteria.JpaSelection) AvailableSettings(org.hibernate.cfg.AvailableSettings) Assertions.assertNotEquals(org.junit.jupiter.api.Assertions.assertNotEquals) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) Session(org.hibernate.Session) Constructor(java.lang.reflect.Constructor) ArrayList(java.util.ArrayList) HibernateProxy(org.hibernate.proxy.HibernateProxy) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) Map(java.util.Map) Query(org.hibernate.query.Query) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) SessionFactoryImplementor(org.hibernate.engine.spi.SessionFactoryImplementor) Order(jakarta.persistence.criteria.Order) BigIntJdbcType(org.hibernate.type.descriptor.jdbc.BigIntJdbcType) Transformers(org.hibernate.transform.Transformers) Iterator(java.util.Iterator) ListJoin(jakarta.persistence.criteria.ListJoin) ReflectHelper(org.hibernate.internal.util.ReflectHelper) DomainModel(org.hibernate.testing.orm.junit.DomainModel) AliasToBeanConstructorResultTransformer(org.hibernate.transform.AliasToBeanConstructorResultTransformer) Selection(jakarta.persistence.criteria.Selection) CacheMode(org.hibernate.CacheMode) Assertions.assertSame(org.junit.jupiter.api.Assertions.assertSame) JpaCriteriaQuery(org.hibernate.query.criteria.JpaCriteriaQuery) Test(org.junit.jupiter.api.Test) MapJoin(jakarta.persistence.criteria.MapJoin) List(java.util.List) Root(jakarta.persistence.criteria.Root) SessionFactoryScope(org.hibernate.testing.orm.junit.SessionFactoryScope) CriteriaBuilder(jakarta.persistence.criteria.CriteriaBuilder) JpaRoot(org.hibernate.query.criteria.JpaRoot) LongJavaType(org.hibernate.type.descriptor.java.LongJavaType) Setting(org.hibernate.testing.orm.junit.Setting) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) AliasToEntityMapResultTransformer(org.hibernate.transform.AliasToEntityMapResultTransformer) SessionFactory(org.hibernate.testing.orm.junit.SessionFactory) Path(jakarta.persistence.criteria.Path) Hibernate(org.hibernate.Hibernate) ResultTransformer(org.hibernate.transform.ResultTransformer) Type(org.hibernate.type.Type) Join(jakarta.persistence.criteria.Join) ArrayList(java.util.ArrayList) List(java.util.List) JpaCriteriaQuery(org.hibernate.query.criteria.JpaCriteriaQuery) Session(org.hibernate.Session) Test(org.junit.jupiter.api.Test)

Example 19 with SessionFactoryScope

use of org.hibernate.testing.orm.junit.SessionFactoryScope in project hibernate-orm by hibernate.

the class AbstractQueryCacheResultTransformerTest method testAliasToBeanDtoMultiArgList.

@Test
public void testAliasToBeanDtoMultiArgList(SessionFactoryScope scope) throws Exception {
    CriteriaExecutor criteriaExecutor = new CriteriaExecutor() {

        @Override
        protected ResultTransformer getResultTransformer() {
            return Transformers.aliasToBean(StudentDTO.class);
        }

        @Override
        protected JpaCriteriaQuery getCriteria(Session s) {
            CriteriaBuilder builder = s.getCriteriaBuilder();
            JpaCriteriaQuery criteria = (JpaCriteriaQuery) builder.createQuery();
            Root<Enrolment> root = criteria.from(Enrolment.class);
            final Path<Object> student = root.get("student");
            criteria.multiselect(student.get("name").alias("studentName"), root.get("course").get("description").alias("courseDescription"));
            criteria.orderBy(builder.asc(root.get("studentNumber")));
            return criteria;
        // return s.createCriteria( Enrolment.class, "e" )
        // .createAlias( "e.student", "st" )
        // .createAlias( "e.course", "co" )
        // .setProjection(
        // Projections.projectionList()
        // .add( Property.forName( "st.name" ).as( "studentName" ) )
        // .add( Property.forName( "co.description" ).as( "courseDescription" ) )
        // )
        // .addOrder( Order.asc( "e.studentNumber" ) )
        // .setResultTransformer( Transformers.aliasToBean( StudentDTO.class ) );
        }
    };
    HqlExecutor hqlExecutor = new HqlExecutor() {

        @Override
        public Query getQuery(Session s) {
            return s.createQuery("select st.name as studentName, co.description as courseDescription from Enrolment e join e.student st join e.course co order by e.studentNumber").setResultTransformer(Transformers.aliasToBean(StudentDTO.class));
        }
    };
    ResultChecker checker = results -> {
        List resultList = (List) results;
        assertEquals(2, resultList.size());
        StudentDTO dto = (StudentDTO) resultList.get(0);
        assertEquals(courseExpected.getDescription(), dto.getDescription());
        assertEquals(yogiExpected.getName(), dto.getName());
        dto = (StudentDTO) resultList.get(1);
        assertEquals(courseExpected.getDescription(), dto.getDescription());
        assertEquals(shermanExpected.getName(), dto.getName());
    };
    runTest(hqlExecutor, criteriaExecutor, checker, false, scope);
}
Also used : CriteriaBuilder(jakarta.persistence.criteria.CriteriaBuilder) BasicTypeImpl(org.hibernate.type.internal.BasicTypeImpl) ServiceRegistry(org.hibernate.testing.orm.junit.ServiceRegistry) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) JoinType(jakarta.persistence.criteria.JoinType) JpaSelection(org.hibernate.query.criteria.JpaSelection) AvailableSettings(org.hibernate.cfg.AvailableSettings) Assertions.assertNotEquals(org.junit.jupiter.api.Assertions.assertNotEquals) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) Session(org.hibernate.Session) Constructor(java.lang.reflect.Constructor) ArrayList(java.util.ArrayList) HibernateProxy(org.hibernate.proxy.HibernateProxy) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) Map(java.util.Map) Query(org.hibernate.query.Query) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) SessionFactoryImplementor(org.hibernate.engine.spi.SessionFactoryImplementor) Order(jakarta.persistence.criteria.Order) BigIntJdbcType(org.hibernate.type.descriptor.jdbc.BigIntJdbcType) Transformers(org.hibernate.transform.Transformers) Iterator(java.util.Iterator) ListJoin(jakarta.persistence.criteria.ListJoin) ReflectHelper(org.hibernate.internal.util.ReflectHelper) DomainModel(org.hibernate.testing.orm.junit.DomainModel) AliasToBeanConstructorResultTransformer(org.hibernate.transform.AliasToBeanConstructorResultTransformer) Selection(jakarta.persistence.criteria.Selection) CacheMode(org.hibernate.CacheMode) Assertions.assertSame(org.junit.jupiter.api.Assertions.assertSame) JpaCriteriaQuery(org.hibernate.query.criteria.JpaCriteriaQuery) Test(org.junit.jupiter.api.Test) MapJoin(jakarta.persistence.criteria.MapJoin) List(java.util.List) Root(jakarta.persistence.criteria.Root) SessionFactoryScope(org.hibernate.testing.orm.junit.SessionFactoryScope) CriteriaBuilder(jakarta.persistence.criteria.CriteriaBuilder) JpaRoot(org.hibernate.query.criteria.JpaRoot) LongJavaType(org.hibernate.type.descriptor.java.LongJavaType) Setting(org.hibernate.testing.orm.junit.Setting) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) AliasToEntityMapResultTransformer(org.hibernate.transform.AliasToEntityMapResultTransformer) SessionFactory(org.hibernate.testing.orm.junit.SessionFactory) Path(jakarta.persistence.criteria.Path) Hibernate(org.hibernate.Hibernate) ResultTransformer(org.hibernate.transform.ResultTransformer) Type(org.hibernate.type.Type) Join(jakarta.persistence.criteria.Join) ArrayList(java.util.ArrayList) List(java.util.List) JpaCriteriaQuery(org.hibernate.query.criteria.JpaCriteriaQuery) Session(org.hibernate.Session) Test(org.junit.jupiter.api.Test)

Example 20 with SessionFactoryScope

use of org.hibernate.testing.orm.junit.SessionFactoryScope in project hibernate-orm by hibernate.

the class AbstractQueryCacheResultTransformerTest method testMapKeyList.

@Test
public void testMapKeyList(SessionFactoryScope scope) throws Exception {
    CriteriaExecutor criteriaExecutor = new CriteriaExecutor() {

        @Override
        protected ResultTransformer getResultTransformer() {
            return null;
        }

        @Override
        protected JpaCriteriaQuery getCriteria(Session s) {
            CriteriaBuilder builder = s.getCriteriaBuilder();
            JpaCriteriaQuery criteria = (JpaCriteriaQuery) builder.createQuery();
            Root<Student> root = criteria.from(Student.class);
            final MapJoin<Object, Object, Order> addresses = root.joinMap("addresses", JoinType.INNER);
            criteria.select(addresses.key());
            /*
						s.createCriteria( Student.class, "s" )
								.createAlias( "s.addresses", "a", Criteria.INNER_JOIN )
								.setProjection( Projections.property( "s.addresses" ) );
				 */
            return criteria;
        }
    };
    HqlExecutor hqlExecutor = new HqlExecutor() {

        @Override
        public Query getQuery(Session s) {
            return s.createQuery("select key(s.addresses) from Student s");
        }
    };
    ResultChecker checker = results -> {
        List resultList = (List) results;
        assertEquals(2, resultList.size());
        assertTrue(resultList.contains("home"));
        assertTrue(resultList.contains("work"));
    };
    runTest(hqlExecutor, criteriaExecutor, checker, false, scope);
}
Also used : CriteriaBuilder(jakarta.persistence.criteria.CriteriaBuilder) Order(jakarta.persistence.criteria.Order) BasicTypeImpl(org.hibernate.type.internal.BasicTypeImpl) ServiceRegistry(org.hibernate.testing.orm.junit.ServiceRegistry) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) JoinType(jakarta.persistence.criteria.JoinType) JpaSelection(org.hibernate.query.criteria.JpaSelection) AvailableSettings(org.hibernate.cfg.AvailableSettings) Assertions.assertNotEquals(org.junit.jupiter.api.Assertions.assertNotEquals) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) Session(org.hibernate.Session) Constructor(java.lang.reflect.Constructor) ArrayList(java.util.ArrayList) HibernateProxy(org.hibernate.proxy.HibernateProxy) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) Map(java.util.Map) Query(org.hibernate.query.Query) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) SessionFactoryImplementor(org.hibernate.engine.spi.SessionFactoryImplementor) Order(jakarta.persistence.criteria.Order) BigIntJdbcType(org.hibernate.type.descriptor.jdbc.BigIntJdbcType) Transformers(org.hibernate.transform.Transformers) Iterator(java.util.Iterator) ListJoin(jakarta.persistence.criteria.ListJoin) ReflectHelper(org.hibernate.internal.util.ReflectHelper) DomainModel(org.hibernate.testing.orm.junit.DomainModel) AliasToBeanConstructorResultTransformer(org.hibernate.transform.AliasToBeanConstructorResultTransformer) Selection(jakarta.persistence.criteria.Selection) CacheMode(org.hibernate.CacheMode) Assertions.assertSame(org.junit.jupiter.api.Assertions.assertSame) JpaCriteriaQuery(org.hibernate.query.criteria.JpaCriteriaQuery) Test(org.junit.jupiter.api.Test) MapJoin(jakarta.persistence.criteria.MapJoin) List(java.util.List) Root(jakarta.persistence.criteria.Root) SessionFactoryScope(org.hibernate.testing.orm.junit.SessionFactoryScope) CriteriaBuilder(jakarta.persistence.criteria.CriteriaBuilder) JpaRoot(org.hibernate.query.criteria.JpaRoot) LongJavaType(org.hibernate.type.descriptor.java.LongJavaType) Setting(org.hibernate.testing.orm.junit.Setting) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) AliasToEntityMapResultTransformer(org.hibernate.transform.AliasToEntityMapResultTransformer) SessionFactory(org.hibernate.testing.orm.junit.SessionFactory) Path(jakarta.persistence.criteria.Path) Hibernate(org.hibernate.Hibernate) ResultTransformer(org.hibernate.transform.ResultTransformer) Type(org.hibernate.type.Type) Join(jakarta.persistence.criteria.Join) ArrayList(java.util.ArrayList) List(java.util.List) JpaCriteriaQuery(org.hibernate.query.criteria.JpaCriteriaQuery) Session(org.hibernate.Session) Test(org.junit.jupiter.api.Test)

Aggregations

SessionFactoryScope (org.hibernate.testing.orm.junit.SessionFactoryScope)68 DomainModel (org.hibernate.testing.orm.junit.DomainModel)67 SessionFactory (org.hibernate.testing.orm.junit.SessionFactory)67 Test (org.junit.jupiter.api.Test)67 ServiceRegistry (org.hibernate.testing.orm.junit.ServiceRegistry)64 Setting (org.hibernate.testing.orm.junit.Setting)64 Assertions.assertTrue (org.junit.jupiter.api.Assertions.assertTrue)64 List (java.util.List)63 AvailableSettings (org.hibernate.cfg.AvailableSettings)63 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)63 Assertions.assertFalse (org.junit.jupiter.api.Assertions.assertFalse)63 Query (org.hibernate.query.Query)62 CriteriaBuilder (jakarta.persistence.criteria.CriteriaBuilder)61 Root (jakarta.persistence.criteria.Root)61 ArrayList (java.util.ArrayList)61 CacheMode (org.hibernate.CacheMode)61 Hibernate (org.hibernate.Hibernate)61 Session (org.hibernate.Session)61 ReflectHelper (org.hibernate.internal.util.ReflectHelper)61 ResultTransformer (org.hibernate.transform.ResultTransformer)61