Search in sources :

Example 1 with HibernateCriteriaBuilder

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

the class PluralAttributeExpressionsTest method testEntityMapIsEmptyCriteria.

@Test
@TestForIssue(jiraKey = "HHH-11225")
public void testEntityMapIsEmptyCriteria() {
    doInJPA(this::entityManagerFactory, entityManager -> {
        final HibernateCriteriaBuilder cb = (HibernateCriteriaBuilder) entityManager.getCriteriaBuilder();
        final CriteriaQuery<Article> criteria = cb.createQuery(Article.class);
        final Root<Article> root = criteria.from(Article.class);
        criteria.select(root).where(cb.isEmpty(root.get(Article_.translations)));
        entityManager.createQuery(criteria).getResultList();
    });
}
Also used : Article(org.hibernate.jpa.test.metamodel.Article) HibernateCriteriaBuilder(org.hibernate.query.criteria.HibernateCriteriaBuilder) Test(org.junit.Test) AbstractMetamodelSpecificTest(org.hibernate.jpa.test.metamodel.AbstractMetamodelSpecificTest) TestForIssue(org.hibernate.testing.TestForIssue)

Example 2 with HibernateCriteriaBuilder

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

the class PluralAttributeExpressionsTest method testEntityMapSizeCriteria.

@Test
@TestForIssue(jiraKey = "HHH-11225")
public void testEntityMapSizeCriteria() {
    doInJPA(this::entityManagerFactory, entityManager -> {
        final HibernateCriteriaBuilder cb = (HibernateCriteriaBuilder) entityManager.getCriteriaBuilder();
        final CriteriaQuery<Article> criteria = cb.createQuery(Article.class);
        final Root<Article> root = criteria.from(Article.class);
        criteria.select(root).where(cb.gt(cb.mapSize(root.get(Article_.translations)), 1));
        entityManager.createQuery(criteria).getResultList();
    });
}
Also used : Article(org.hibernate.jpa.test.metamodel.Article) HibernateCriteriaBuilder(org.hibernate.query.criteria.HibernateCriteriaBuilder) Test(org.junit.Test) AbstractMetamodelSpecificTest(org.hibernate.jpa.test.metamodel.AbstractMetamodelSpecificTest) TestForIssue(org.hibernate.testing.TestForIssue)

Example 3 with HibernateCriteriaBuilder

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

the class PluralAttributeExpressionsTest method testCollectionIsEmptyCriteria.

@Test
public void testCollectionIsEmptyCriteria() {
    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.isEmpty(root.get(Address_.phones)));
        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)

Example 4 with HibernateCriteriaBuilder

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

the class PluralAttributeExpressionsTest method testElementMapSizeCriteria.

@Test
@TestForIssue(jiraKey = "HHH-11225")
public void testElementMapSizeCriteria() {
    doInJPA(this::entityManagerFactory, entityManager -> {
        final HibernateCriteriaBuilder cb = (HibernateCriteriaBuilder) entityManager.getCriteriaBuilder();
        final CriteriaQuery<MapEntity> criteria = cb.createQuery(MapEntity.class);
        final Root<MapEntity> root = criteria.from(MapEntity.class);
        criteria.select(root).where(cb.gt(cb.mapSize(root.get(MapEntity_.localized)), 1));
        entityManager.createQuery(criteria).getResultList();
    });
}
Also used : HibernateCriteriaBuilder(org.hibernate.query.criteria.HibernateCriteriaBuilder) MapEntity(org.hibernate.jpa.test.metamodel.MapEntity) Test(org.junit.Test) AbstractMetamodelSpecificTest(org.hibernate.jpa.test.metamodel.AbstractMetamodelSpecificTest) TestForIssue(org.hibernate.testing.TestForIssue)

Example 5 with HibernateCriteriaBuilder

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

the class PluralAttributeExpressionsTest method testElementMapIsEmptyCriteria.

@Test
@TestForIssue(jiraKey = "HHH-11225")
@FailureExpected(jiraKey = "HHH-6686")
public void testElementMapIsEmptyCriteria() {
    doInJPA(this::entityManagerFactory, entityManager -> {
        final HibernateCriteriaBuilder cb = (HibernateCriteriaBuilder) entityManager.getCriteriaBuilder();
        final CriteriaQuery<MapEntity> criteria = cb.createQuery(MapEntity.class);
        final Root<MapEntity> root = criteria.from(MapEntity.class);
        criteria.select(root).where(cb.isMapEmpty(root.get(MapEntity_.localized)));
        entityManager.createQuery(criteria).getResultList();
    });
}
Also used : HibernateCriteriaBuilder(org.hibernate.query.criteria.HibernateCriteriaBuilder) MapEntity(org.hibernate.jpa.test.metamodel.MapEntity) Test(org.junit.Test) AbstractMetamodelSpecificTest(org.hibernate.jpa.test.metamodel.AbstractMetamodelSpecificTest) FailureExpected(org.hibernate.testing.FailureExpected) TestForIssue(org.hibernate.testing.TestForIssue)

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