Search in sources :

Example 16 with BasicEntity

use of org.hibernate.testing.orm.domain.gambit.BasicEntity in project hibernate-orm by hibernate.

the class MultiSelectTests method simpleArrayTest.

@Test
public void simpleArrayTest(SessionFactoryScope scope) {
    scope.inTransaction((session) -> {
        final CriteriaBuilder nodeBuilder = session.getFactory().getNodeBuilder();
        final CriteriaQuery criteria = nodeBuilder.createQuery();
        final Root<BasicEntity> root = criteria.from(BasicEntity.class);
        final EntityType<BasicEntity> model = root.getModel();
        criteria.select(nodeBuilder.array(root.get(model.getDeclaredSingularAttribute("id", Integer.class)), root.get(model.getDeclaredSingularAttribute("data", String.class))));
        final List<Object[]> results = session.createQuery(criteria).list();
        assertThat(results).hasSize(1);
        final Object[] firstResult = results.get(0);
        assertThat(firstResult[0]).isEqualTo(1);
        assertThat(firstResult[1]).isEqualTo("abc");
    });
}
Also used : CriteriaBuilder(jakarta.persistence.criteria.CriteriaBuilder) CriteriaQuery(jakarta.persistence.criteria.CriteriaQuery) BasicEntity(org.hibernate.testing.orm.domain.gambit.BasicEntity) Test(org.junit.jupiter.api.Test)

Example 17 with BasicEntity

use of org.hibernate.testing.orm.domain.gambit.BasicEntity in project hibernate-orm by hibernate.

the class MultiSelectTests method singleSelectionTupleTest.

@Test
public void singleSelectionTupleTest(SessionFactoryScope scope) {
    scope.inTransaction((session) -> {
        final CriteriaBuilder nodeBuilder = session.getFactory().getNodeBuilder();
        final CriteriaQuery criteria = nodeBuilder.createTupleQuery();
        final Root<BasicEntity> root = criteria.from(BasicEntity.class);
        final EntityType<BasicEntity> model = root.getModel();
        criteria.select(root.get(model.getDeclaredSingularAttribute("id", Integer.class)));
        final List<Tuple> results = session.createQuery(criteria).list();
        assertThat(results).hasSize(1);
        final Tuple firstResult = results.get(0);
        assertThat(firstResult.get(0)).isEqualTo(1);
    });
}
Also used : CriteriaBuilder(jakarta.persistence.criteria.CriteriaBuilder) CriteriaQuery(jakarta.persistence.criteria.CriteriaQuery) Tuple(jakarta.persistence.Tuple) BasicEntity(org.hibernate.testing.orm.domain.gambit.BasicEntity) Test(org.junit.jupiter.api.Test)

Example 18 with BasicEntity

use of org.hibernate.testing.orm.domain.gambit.BasicEntity in project hibernate-orm by hibernate.

the class SubQueryTests method modifiedSubQueryHqlTest.

@Test
public void modifiedSubQueryHqlTest(SessionFactoryScope scope) {
    scope.inTransaction((session) -> {
        session.persist(new BasicEntity(2368, "irrelevant"));
        session.persist(new BasicEntity(2578, "irrelevant"));
        session.persist(new BasicEntity(3000, "irrelevant"));
        session.persist(new BasicEntity(10000, "irrelevant"));
        session.persist(new BasicEntity(10050, "irrelevant"));
    });
    scope.inTransaction((session) -> {
        final String qry = "select e.id from BasicEntity e where e.id > all (select s.id from BasicEntity s where s.id > 1)";
        session.createQuery(qry).list();
    });
}
Also used : BasicEntity(org.hibernate.testing.orm.domain.gambit.BasicEntity) Test(org.junit.jupiter.api.Test)

Example 19 with BasicEntity

use of org.hibernate.testing.orm.domain.gambit.BasicEntity in project hibernate-orm by hibernate.

the class BasicCriteriaExecutionTests method testExecutingBasicCriteriaQueryLiteralPredicate.

@Test
public void testExecutingBasicCriteriaQueryLiteralPredicate(SessionFactoryScope scope) {
    scope.inTransaction(session -> {
        final HibernateCriteriaBuilder criteriaBuilder = session.getCriteriaBuilder();
        final CriteriaQuery<Object> criteria = criteriaBuilder.createQuery();
        final Root<BasicEntity> root = criteria.from(BasicEntity.class);
        criteria.select(root);
        criteria.where(criteriaBuilder.equal(criteriaBuilder.literal(1), criteriaBuilder.literal(1)));
        session.createQuery(criteria).list();
    });
}
Also used : HibernateCriteriaBuilder(org.hibernate.query.criteria.HibernateCriteriaBuilder) BasicEntity(org.hibernate.testing.orm.domain.gambit.BasicEntity) Test(org.junit.jupiter.api.Test)

Example 20 with BasicEntity

use of org.hibernate.testing.orm.domain.gambit.BasicEntity in project hibernate-orm by hibernate.

the class BasicCriteriaExecutionTests method testCriteriaEntityJoin.

@Test
public void testCriteriaEntityJoin(SessionFactoryScope scope) {
    scope.inStatelessTransaction(session -> {
        final HibernateCriteriaBuilder criteriaBuilder = session.getCriteriaBuilder();
        final JpaCriteriaQuery<Object> criteria = criteriaBuilder.createQuery();
        final JpaRoot<BasicEntity> root = criteria.from(BasicEntity.class);
        root.join(BasicEntity.class, SqmJoinType.CROSS);
        criteria.select(root);
        session.createQuery(criteria).list();
    });
}
Also used : HibernateCriteriaBuilder(org.hibernate.query.criteria.HibernateCriteriaBuilder) BasicEntity(org.hibernate.testing.orm.domain.gambit.BasicEntity) Test(org.junit.jupiter.api.Test)

Aggregations

BasicEntity (org.hibernate.testing.orm.domain.gambit.BasicEntity)44 Test (org.junit.jupiter.api.Test)39 HibernateCriteriaBuilder (org.hibernate.query.criteria.HibernateCriteriaBuilder)23 CriteriaBuilder (jakarta.persistence.criteria.CriteriaBuilder)15 CriteriaQuery (jakarta.persistence.criteria.CriteriaQuery)11 List (java.util.List)8 Query (org.hibernate.query.Query)8 Tuple (jakarta.persistence.Tuple)6 BeforeEach (org.junit.jupiter.api.BeforeEach)3 Collection (java.util.Collection)2 JoinedInheritanceTest (org.hibernate.orm.test.mapping.inheritance.joined.JoinedInheritanceTest)2 StatisticsImplementor (org.hibernate.stat.spi.StatisticsImplementor)2 SkipForDialect (org.hibernate.testing.SkipForDialect)2 EntityWithManyToOneJoinTable (org.hibernate.testing.orm.domain.gambit.EntityWithManyToOneJoinTable)2 SimpleEntity (org.hibernate.testing.orm.domain.gambit.SimpleEntity)2 RequiresDialect (org.hibernate.testing.orm.junit.RequiresDialect)2 BeforeAll (org.junit.jupiter.api.BeforeAll)2 Selection (jakarta.persistence.criteria.Selection)1 ArrayList (java.util.ArrayList)1 SingleIdEntityLoaderStandardImpl (org.hibernate.loader.ast.internal.SingleIdEntityLoaderStandardImpl)1