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();
}
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();
}
}
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();
}
}
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();
}
}
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();
}
}
Aggregations