Search in sources :

Example 6 with CriteriaQuery

use of jakarta.persistence.criteria.CriteriaQuery 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 CriteriaQuery

use of jakarta.persistence.criteria.CriteriaQuery 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 CriteriaQuery

use of jakarta.persistence.criteria.CriteriaQuery 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 CriteriaQuery

use of jakarta.persistence.criteria.CriteriaQuery 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 CriteriaQuery

use of jakarta.persistence.criteria.CriteriaQuery 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

CriteriaQuery (jakarta.persistence.criteria.CriteriaQuery)96 CriteriaBuilder (jakarta.persistence.criteria.CriteriaBuilder)82 EntityManager (jakarta.persistence.EntityManager)64 Query (jakarta.persistence.Query)63 List (java.util.List)54 TypedQuery (jakarta.persistence.TypedQuery)35 Employee (org.eclipse.persistence.testing.models.jpa.advanced.Employee)32 Test (org.junit.jupiter.api.Test)24 JpaQuery (org.eclipse.persistence.jpa.JpaQuery)20 JpaEntityManager (org.eclipse.persistence.jpa.JpaEntityManager)16 JpaCriteriaBuilder (org.eclipse.persistence.jpa.JpaCriteriaBuilder)14 Test (org.junit.Test)14 ArrayList (java.util.ArrayList)13 ReportQuery (org.eclipse.persistence.queries.ReportQuery)12 Query (org.hibernate.query.Query)12 QuerySQLTracker (org.eclipse.persistence.testing.framework.QuerySQLTracker)11 BasicEntity (org.hibernate.testing.orm.domain.gambit.BasicEntity)11 Root (jakarta.persistence.criteria.Root)8 HibernateCriteriaBuilder (org.hibernate.query.criteria.HibernateCriteriaBuilder)8 DatabasePlatform (org.eclipse.persistence.platform.database.DatabasePlatform)7