RegionService extends AbstractInfrastructureAdoService<Region> { public List<Region> getByName(String name, boolean includeArchivedEntities) { CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<Region> cq = cb.createQuery(getElementClass()); Root<Region> from = cq.from(getElementClass()); Predicate filter = cb .or(cb.equal(cb.trim(from.get(Region.NAME)), name.trim()), cb.equal(cb.lower(cb.trim(from.get(Region.NAME))), name.trim().toLowerCase())); if (!includeArchivedEntities) { filter = cb.and(filter, createBasicFilter(cb, from)); } cq.where(filter); return em.createQuery(cq).getResultList(); } RegionService(); List<Region> getByName(String name, boolean includeArchivedEntities); @SuppressWarnings("rawtypes") @Override Predicate createUserFilter(CriteriaBuilder cb, CriteriaQuery cq, From<?, Region> from); Predicate buildCriteriaFilter(RegionCriteria criteria, CriteriaBuilder cb, Root<Region> from);  }
@Test public void testGetByName() { creator.createRegion("Region"); assertThat(getRegionService().getByName("Region", true), hasSize(1)); assertThat(getRegionService().getByName(" Region ", true), hasSize(1)); assertThat(getRegionService().getByName("region", true), hasSize(1)); assertThat(getRegionService().getByName("REGION", true), hasSize(1)); assertThat(getRegionService().getByName("The Hinterlands", true), empty()); }