Search in sources :

Example 6 with HibernateCriteriaBuilder

use of org.hibernate.query.criteria.HibernateCriteriaBuilder in project hibernate-orm by hibernate.

the class PluralAttributeExpressionsTest method testCollectionSizeCriteria.

@Test
public void testCollectionSizeCriteria() {
    doInJPA(this::entityManagerFactory, entityManager -> {
        final HibernateCriteriaBuilder cb = (HibernateCriteriaBuilder) entityManager.getCriteriaBuilder();
        final CriteriaQuery<Address> criteria = cb.createQuery(Address.class);
        final Root<Address> root = criteria.from(Address.class);
        criteria.select(root).where(cb.gt(cb.size(root.get(Address_.phones)), 1));
        entityManager.createQuery(criteria).getResultList();
    });
}
Also used : Address(org.hibernate.jpa.test.metamodel.Address) HibernateCriteriaBuilder(org.hibernate.query.criteria.HibernateCriteriaBuilder) Test(org.junit.Test) AbstractMetamodelSpecificTest(org.hibernate.jpa.test.metamodel.AbstractMetamodelSpecificTest)

Aggregations

AbstractMetamodelSpecificTest (org.hibernate.jpa.test.metamodel.AbstractMetamodelSpecificTest)6 HibernateCriteriaBuilder (org.hibernate.query.criteria.HibernateCriteriaBuilder)6 Test (org.junit.Test)6 TestForIssue (org.hibernate.testing.TestForIssue)4 Address (org.hibernate.jpa.test.metamodel.Address)2 Article (org.hibernate.jpa.test.metamodel.Article)2 MapEntity (org.hibernate.jpa.test.metamodel.MapEntity)2 FailureExpected (org.hibernate.testing.FailureExpected)1