Search in sources :

Example 6 with BasicEntity

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

the class ILikeCriteriaTest method testNotIlike.

@Test
public void testNotIlike(SessionFactoryScope scope) {
    scope.inTransaction(session -> {
        HibernateCriteriaBuilder cb = session.getCriteriaBuilder();
        CriteriaQuery cq = cb.createQuery(BasicEntity.class);
        Root<BasicEntity> from = cq.from(BasicEntity.class);
        cq.where(cb.notIlike(from.get("data"), "Produ%"));
        Query q = session.createQuery(cq);
        List l = q.getResultList();
        assertEquals(4, l.size());
        cq.where(cb.notIlike(from.get("data"), cb.literal("Produ%")));
        q = session.createQuery(cq);
        l = q.getResultList();
        assertEquals(4, l.size());
    });
}
Also used : CriteriaQuery(jakarta.persistence.criteria.CriteriaQuery) Query(org.hibernate.query.Query) CriteriaQuery(jakarta.persistence.criteria.CriteriaQuery) List(java.util.List) HibernateCriteriaBuilder(org.hibernate.query.criteria.HibernateCriteriaBuilder) BasicEntity(org.hibernate.testing.orm.domain.gambit.BasicEntity) Test(org.junit.jupiter.api.Test)

Example 7 with BasicEntity

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

the class ILikeCriteriaTest method testNotLike.

@Test
public void testNotLike(SessionFactoryScope scope) {
    scope.inTransaction(session -> {
        HibernateCriteriaBuilder cb = session.getCriteriaBuilder();
        CriteriaQuery cq = cb.createQuery(BasicEntity.class);
        Root<BasicEntity> from = cq.from(BasicEntity.class);
        cq.where(cb.notLike(from.get("data"), "Prod%"));
        Query q = session.createQuery(cq);
        List l = q.getResultList();
        assertEquals(4, l.size());
        cq.where(cb.notLike(from.get("data"), cb.literal("Prod%")));
        q = session.createQuery(cq);
        l = q.getResultList();
        assertEquals(4, l.size());
    });
}
Also used : CriteriaQuery(jakarta.persistence.criteria.CriteriaQuery) Query(org.hibernate.query.Query) CriteriaQuery(jakarta.persistence.criteria.CriteriaQuery) List(java.util.List) HibernateCriteriaBuilder(org.hibernate.query.criteria.HibernateCriteriaBuilder) BasicEntity(org.hibernate.testing.orm.domain.gambit.BasicEntity) Test(org.junit.jupiter.api.Test)

Example 8 with BasicEntity

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

the class ILikeCriteriaTest method testLikeEscape.

@Test
public void testLikeEscape(SessionFactoryScope scope) {
    scope.inTransaction(session -> {
        HibernateCriteriaBuilder cb = session.getCriteriaBuilder();
        CriteriaQuery cq = cb.createQuery(BasicEntity.class);
        Root<BasicEntity> from = cq.from(BasicEntity.class);
        cq.where(cb.like(from.get("data"), cb.literal("Prod%"), cb.literal('$')));
        Query q = session.createQuery(cq);
        List l = q.getResultList();
        assertEquals(5, l.size());
        cq.where(cb.like(from.get("data"), cb.literal("Prod%"), '$'));
        q = session.createQuery(cq);
        l = q.getResultList();
        assertEquals(5, l.size());
        cq.where(cb.like(from.get("data"), "Prod%", cb.literal('$')));
        q = session.createQuery(cq);
        l = q.getResultList();
        assertEquals(5, l.size());
        cq.where(cb.like(from.get("data"), "Prod%", '$'));
        q = session.createQuery(cq);
        l = q.getResultList();
        assertEquals(5, l.size());
    });
}
Also used : CriteriaQuery(jakarta.persistence.criteria.CriteriaQuery) Query(org.hibernate.query.Query) CriteriaQuery(jakarta.persistence.criteria.CriteriaQuery) List(java.util.List) HibernateCriteriaBuilder(org.hibernate.query.criteria.HibernateCriteriaBuilder) BasicEntity(org.hibernate.testing.orm.domain.gambit.BasicEntity) Test(org.junit.jupiter.api.Test)

Example 9 with BasicEntity

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

the class ILikeCriteriaTest method testIlikeEscape.

@Test
public void testIlikeEscape(SessionFactoryScope scope) {
    scope.inTransaction(session -> {
        HibernateCriteriaBuilder cb = session.getCriteriaBuilder();
        CriteriaQuery cq = cb.createQuery(BasicEntity.class);
        Root<BasicEntity> from = cq.from(BasicEntity.class);
        cq.where(cb.ilike(from.get("data"), cb.literal("Pr%$_%"), cb.literal('$')));
        Query q = session.createQuery(cq);
        List l = q.getResultList();
        assertEquals(3, l.size());
        cq.where(cb.ilike(from.get("data"), cb.literal("Pr%$_%"), '$'));
        q = session.createQuery(cq);
        l = q.getResultList();
        assertEquals(3, l.size());
        cq.where(cb.ilike(from.get("data"), "Pr%$_%", cb.literal('$')));
        q = session.createQuery(cq);
        l = q.getResultList();
        assertEquals(3, l.size());
        cq.where(cb.ilike(from.get("data"), "Pr%$_%", '$'));
        q = session.createQuery(cq);
        l = q.getResultList();
        assertEquals(3, l.size());
    });
}
Also used : CriteriaQuery(jakarta.persistence.criteria.CriteriaQuery) Query(org.hibernate.query.Query) CriteriaQuery(jakarta.persistence.criteria.CriteriaQuery) List(java.util.List) HibernateCriteriaBuilder(org.hibernate.query.criteria.HibernateCriteriaBuilder) BasicEntity(org.hibernate.testing.orm.domain.gambit.BasicEntity) Test(org.junit.jupiter.api.Test)

Example 10 with BasicEntity

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

the class ILikeCriteriaTest method testLike.

@Test
public void testLike(SessionFactoryScope scope) {
    scope.inTransaction(session -> {
        HibernateCriteriaBuilder cb = session.getCriteriaBuilder();
        CriteriaQuery cq = cb.createQuery(BasicEntity.class);
        Root<BasicEntity> from = cq.from(BasicEntity.class);
        cq.where(cb.like(from.get("data"), "Prod%"));
        Query q = session.createQuery(cq);
        List l = q.getResultList();
        assertEquals(5, l.size());
        cq.where(cb.like(from.get("data"), cb.literal("Prod%")));
        q = session.createQuery(cq);
        l = q.getResultList();
        assertEquals(5, l.size());
    });
}
Also used : CriteriaQuery(jakarta.persistence.criteria.CriteriaQuery) Query(org.hibernate.query.Query) CriteriaQuery(jakarta.persistence.criteria.CriteriaQuery) List(java.util.List) 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