Search in sources :

Example 41 with BasicEntity

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

the class ILikeTest method prepareData.

@BeforeEach
public void prepareData(SessionFactoryScope scope) {
    scope.inTransaction(em -> {
        BasicEntity be1 = new BasicEntity(1, "Product_one");
        em.persist(be1);
        BasicEntity be2 = new BasicEntity(2, "proDUct two");
        em.persist(be2);
        BasicEntity be3 = new BasicEntity(3, "Product three");
        em.persist(be3);
        BasicEntity be4 = new BasicEntity(4, "pROducT four");
        em.persist(be4);
        BasicEntity be5 = new BasicEntity(5, "Product five");
        em.persist(be5);
        BasicEntity be6 = new BasicEntity(6, "Prodact six");
        em.persist(be6);
        BasicEntity be7 = new BasicEntity(7, "prodACt seven");
        em.persist(be7);
        BasicEntity be8 = new BasicEntity(8, "Prod_act eight");
        em.persist(be8);
        BasicEntity be9 = new BasicEntity(9, "prod_ACt nine");
        em.persist(be9);
    });
}
Also used : BasicEntity(org.hibernate.testing.orm.domain.gambit.BasicEntity) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 42 with BasicEntity

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

the class ILikeCriteriaTest method testNotLikeEscape.

@Test
public void testNotLikeEscape(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"), cb.literal("Pr%$_%"), cb.literal('$')));
        Query q = session.createQuery(cq);
        List l = q.getResultList();
        assertEquals(7, l.size());
        cq.where(cb.notLike(from.get("data"), cb.literal("Pr%$_%"), '$'));
        q = session.createQuery(cq);
        l = q.getResultList();
        assertEquals(7, l.size());
        cq.where(cb.notLike(from.get("data"), "Pr%$_%", cb.literal('$')));
        q = session.createQuery(cq);
        l = q.getResultList();
        assertEquals(7, l.size());
        cq.where(cb.notLike(from.get("data"), "Pr%$_%", '$'));
        q = session.createQuery(cq);
        l = q.getResultList();
        assertEquals(7, 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 43 with BasicEntity

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

the class ILikeCriteriaTest method testIlike.

@Test
public void testIlike(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"), "Produ%"));
        Query q = session.createQuery(cq);
        List l = q.getResultList();
        assertEquals(5, l.size());
        cq.where(cb.ilike(from.get("data"), cb.literal("Produ%")));
        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 44 with BasicEntity

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

the class ILikeCriteriaTest method testNotIlikeEscape.

@Test
public void testNotIlikeEscape(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"), cb.literal("Pr%$_%"), cb.literal('$')));
        Query q = session.createQuery(cq);
        List l = q.getResultList();
        assertEquals(6, l.size());
        cq.where(cb.notIlike(from.get("data"), cb.literal("Pr%$_%"), '$'));
        q = session.createQuery(cq);
        l = q.getResultList();
        assertEquals(6, l.size());
        cq.where(cb.notIlike(from.get("data"), "Pr%$_%", cb.literal('$')));
        q = session.createQuery(cq);
        l = q.getResultList();
        assertEquals(6, l.size());
        cq.where(cb.notIlike(from.get("data"), "Pr%$_%", '$'));
        q = session.createQuery(cq);
        l = q.getResultList();
        assertEquals(6, 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