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());
});
}
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());
});
}
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());
});
}
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());
});
}
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());
});
}
Aggregations