Search in sources :

Example 1 with MapEntity

use of org.hibernate.jpa.test.metamodel.MapEntity in project hibernate-orm by hibernate.

the class MapJoinTest method allEntities.

@Test
public void allEntities() {
    EntityManager em = getOrCreateEntityManager();
    em.getTransaction().begin();
    CriteriaBuilder cb = em.getCriteriaBuilder();
    CriteriaQuery<MapEntity> query = cb.createQuery(MapEntity.class);
    Root<MapEntity> entity = query.from(MapEntity.class);
    MapJoin<MapEntity, String, MapEntityLocal> cname = entity.join(MapEntity_.localized);
    query = query.select(entity).where(cb.equal(cname.key(), "en")).orderBy(cb.asc(cb.upper(cname.value().get(MapEntityLocal_.shortName))));
    em.createQuery(query).getResultList();
    em.getTransaction().commit();
    em.close();
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) EntityManager(javax.persistence.EntityManager) MapEntityLocal(org.hibernate.jpa.test.metamodel.MapEntityLocal) MapEntity(org.hibernate.jpa.test.metamodel.MapEntity) Test(org.junit.Test) AbstractMetamodelSpecificTest(org.hibernate.jpa.test.metamodel.AbstractMetamodelSpecificTest)

Example 2 with MapEntity

use of org.hibernate.jpa.test.metamodel.MapEntity 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 3 with MapEntity

use of org.hibernate.jpa.test.metamodel.MapEntity 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)3 MapEntity (org.hibernate.jpa.test.metamodel.MapEntity)3 Test (org.junit.Test)3 HibernateCriteriaBuilder (org.hibernate.query.criteria.HibernateCriteriaBuilder)2 TestForIssue (org.hibernate.testing.TestForIssue)2 EntityManager (javax.persistence.EntityManager)1 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)1 MapEntityLocal (org.hibernate.jpa.test.metamodel.MapEntityLocal)1 FailureExpected (org.hibernate.testing.FailureExpected)1