Search in sources :

Example 21 with BasicEntity

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

the class BasicCriteriaExecutionTests method testExecutingBasicCriteriaQueryParameterPredicate.

// Doing ... where ? = ? ... is only allowed in a few DBs. Since this is useless, we don't bother to emulate this
@Test
@RequiresDialect(H2Dialect.class)
@SkipForDialect(value = DerbyDialect.class, comment = "Derby doesn't support comparing parameters against each other")
public void testExecutingBasicCriteriaQueryParameterPredicate(SessionFactoryScope scope) {
    scope.inStatelessTransaction(session -> {
        final HibernateCriteriaBuilder criteriaBuilder = session.getCriteriaBuilder();
        final CriteriaQuery<Object> criteria = criteriaBuilder.createQuery();
        final Root<BasicEntity> root = criteria.from(BasicEntity.class);
        criteria.select(root);
        final ParameterExpression<Integer> param = criteriaBuilder.parameter(Integer.class);
        criteria.where(criteriaBuilder.equal(param, param));
        session.createQuery(criteria).setParameter(param, 1).list();
    });
}
Also used : HibernateCriteriaBuilder(org.hibernate.query.criteria.HibernateCriteriaBuilder) BasicEntity(org.hibernate.testing.orm.domain.gambit.BasicEntity) SkipForDialect(org.hibernate.testing.SkipForDialect) Test(org.junit.jupiter.api.Test) RequiresDialect(org.hibernate.testing.orm.junit.RequiresDialect)

Example 22 with BasicEntity

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

the class BasicCriteriaExecutionTests method testIt.

@Test
public void testIt(SessionFactoryScope scope) {
    scope.inTransaction(session -> {
        final HibernateCriteriaBuilder criteriaBuilder = session.getCriteriaBuilder();
        CriteriaQuery<BasicEntity> criteria = criteriaBuilder.createQuery(BasicEntity.class);
        criteria.from(BasicEntity.class);
        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 23 with BasicEntity

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

the class BasicCriteriaExecutionTests method testExecutingBasicCriteriaQuery.

@Test
public void testExecutingBasicCriteriaQuery(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);
        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 24 with BasicEntity

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

the class BasicCriteriaExecutionTests method testExecutingBasicCriteriaQueryParameterPredicateInStatelessSession.

// Doing ... where ? = ? ... is only allowed in a few DBs. Since this is useless, we don't bother to emulate this
@Test
@RequiresDialect(H2Dialect.class)
@SkipForDialect(value = DerbyDialect.class, comment = "Derby doesn't support comparing parameters against each other")
public void testExecutingBasicCriteriaQueryParameterPredicateInStatelessSession(SessionFactoryScope scope) {
    scope.inStatelessTransaction(session -> {
        final HibernateCriteriaBuilder criteriaBuilder = session.getCriteriaBuilder();
        final CriteriaQuery<Object> criteria = criteriaBuilder.createQuery();
        final Root<BasicEntity> root = criteria.from(BasicEntity.class);
        criteria.select(root);
        final ParameterExpression<Integer> param = criteriaBuilder.parameter(Integer.class);
        criteria.where(criteriaBuilder.equal(param, param));
        session.createQuery(criteria).setParameter(param, 1).list();
    });
}
Also used : HibernateCriteriaBuilder(org.hibernate.query.criteria.HibernateCriteriaBuilder) BasicEntity(org.hibernate.testing.orm.domain.gambit.BasicEntity) SkipForDialect(org.hibernate.testing.SkipForDialect) Test(org.junit.jupiter.api.Test) RequiresDialect(org.hibernate.testing.orm.junit.RequiresDialect)

Example 25 with BasicEntity

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

the class BasicCriteriaExecutionTests method testExecutingBasicCriteriaQueryInStatelessSession.

@Test
public void testExecutingBasicCriteriaQueryInStatelessSession(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);
        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