Search in sources :

Example 71 with CriteriaQuery

use of javax.persistence.criteria.CriteriaQuery in project hibernate-orm by hibernate.

the class TupleCriteriaTest method testIllegalArgumentExceptionBuildingSelectArrayWithSameAliases.

@Test
public void testIllegalArgumentExceptionBuildingSelectArrayWithSameAliases() {
    EntityManager em = entityManagerFactory().createEntityManager();
    em.getTransaction().begin();
    final CriteriaBuilder builder = em.getCriteriaBuilder();
    CriteriaQuery criteria = builder.createQuery();
    Root<Customer> customerRoot = criteria.from(Customer.class);
    Path<String> namePath = customerRoot.get(Customer_.name);
    Path<Integer> agePath = customerRoot.get(Customer_.age);
    try {
        CompoundSelection<Object[]> c = builder.array(namePath.alias("SAME"), agePath.alias("SAME"));
        criteria.select(c);
        fail("Attempt to define multi-select with same aliases should have thrown IllegalArgumentException");
    } catch (IllegalArgumentException expected) {
    }
    em.getTransaction().commit();
    em.close();
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) EntityManager(javax.persistence.EntityManager) Customer(org.hibernate.jpa.test.metamodel.Customer) CriteriaQuery(javax.persistence.criteria.CriteriaQuery) Test(org.junit.Test) AbstractMetamodelSpecificTest(org.hibernate.jpa.test.metamodel.AbstractMetamodelSpecificTest)

Example 72 with CriteriaQuery

use of javax.persistence.criteria.CriteriaQuery in project OpenAttestation by OpenAttestation.

the class TblMleJpaController method findTblMleEntities.

private List<TblMle> findTblMleEntities(boolean all, int maxResults, int firstResult) {
    EntityManager em = getEntityManager();
    try {
        CriteriaQuery cq = em.getCriteriaBuilder().createQuery();
        cq.select(cq.from(TblMle.class));
        Query q = em.createQuery(cq);
        if (!all) {
            q.setMaxResults(maxResults);
            q.setFirstResult(firstResult);
        }
        return q.getResultList();
    } finally {
        em.close();
    }
}
Also used : EntityManager(javax.persistence.EntityManager) CriteriaQuery(javax.persistence.criteria.CriteriaQuery) Query(javax.persistence.Query) TblMle(com.intel.mtwilson.as.data.TblMle) CriteriaQuery(javax.persistence.criteria.CriteriaQuery)

Example 73 with CriteriaQuery

use of javax.persistence.criteria.CriteriaQuery in project OpenAttestation by OpenAttestation.

the class TblModuleManifestJpaController method findTblModuleManifestEntities.

private List<TblModuleManifest> findTblModuleManifestEntities(boolean all, int maxResults, int firstResult) {
    EntityManager em = getEntityManager();
    try {
        CriteriaQuery cq = em.getCriteriaBuilder().createQuery();
        cq.select(cq.from(TblModuleManifest.class));
        Query q = em.createQuery(cq);
        if (!all) {
            q.setMaxResults(maxResults);
            q.setFirstResult(firstResult);
        }
        return q.getResultList();
    } finally {
        em.close();
    }
}
Also used : EntityManager(javax.persistence.EntityManager) CriteriaQuery(javax.persistence.criteria.CriteriaQuery) Query(javax.persistence.Query) CriteriaQuery(javax.persistence.criteria.CriteriaQuery) TblModuleManifest(com.intel.mtwilson.as.data.TblModuleManifest)

Example 74 with CriteriaQuery

use of javax.persistence.criteria.CriteriaQuery in project OpenAttestation by OpenAttestation.

the class MwMleSourceJpaController method findMwMleSourceEntities.

private List<MwMleSource> findMwMleSourceEntities(boolean all, int maxResults, int firstResult) {
    EntityManager em = getEntityManager();
    try {
        CriteriaQuery cq = em.getCriteriaBuilder().createQuery();
        cq.select(cq.from(MwMleSource.class));
        Query q = em.createQuery(cq);
        if (!all) {
            q.setMaxResults(maxResults);
            q.setFirstResult(firstResult);
        }
        return q.getResultList();
    } finally {
        em.close();
    }
}
Also used : CriteriaQuery(javax.persistence.criteria.CriteriaQuery) Query(javax.persistence.Query) CriteriaQuery(javax.persistence.criteria.CriteriaQuery) MwMleSource(com.intel.mtwilson.as.data.MwMleSource)

Example 75 with CriteriaQuery

use of javax.persistence.criteria.CriteriaQuery in project OpenAttestation by OpenAttestation.

the class TblEventTypeJpaController method getTblEventTypeCount.

public int getTblEventTypeCount() {
    EntityManager em = getEntityManager();
    try {
        CriteriaQuery cq = em.getCriteriaBuilder().createQuery();
        Root<TblEventType> rt = cq.from(TblEventType.class);
        cq.select(em.getCriteriaBuilder().count(rt));
        Query q = em.createQuery(cq);
        return ((Long) q.getSingleResult()).intValue();
    } finally {
        em.close();
    }
}
Also used : EntityManager(javax.persistence.EntityManager) TblEventType(com.intel.mtwilson.as.data.TblEventType) CriteriaQuery(javax.persistence.criteria.CriteriaQuery) Query(javax.persistence.Query) CriteriaQuery(javax.persistence.criteria.CriteriaQuery)

Aggregations

CriteriaQuery (javax.persistence.criteria.CriteriaQuery)155 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)112 EntityManager (javax.persistence.EntityManager)109 Query (javax.persistence.Query)109 TypedQuery (javax.persistence.TypedQuery)69 Predicate (javax.persistence.criteria.Predicate)51 EntityTransaction (javax.persistence.EntityTransaction)45 Root (javax.persistence.criteria.Root)40 List (java.util.List)22 Path (javax.persistence.criteria.Path)18 Test (org.testng.annotations.Test)16 UserTransaction (javax.transaction.UserTransaction)15 Person (org.datanucleus.samples.annotations.models.company.Person)15 Manager (org.datanucleus.samples.jpa.query.Manager)14 Specification (org.springframework.data.jpa.domain.Specification)14 Item (org.jpwh.model.querying.Item)12 Test (org.junit.Test)11 ArrayList (java.util.ArrayList)10 Join (javax.persistence.criteria.Join)10 Session (org.hibernate.Session)9