use of org.hibernate.jpa.test.metamodel.Product in project hibernate-orm by hibernate.
the class AggregationResultTest method testSumOfBigDecimals.
/**
* Sum of BigDecimal should return a BigDecimal
*/
@Test
public void testSumOfBigDecimals() {
EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
CriteriaQuery<BigDecimal> criteria = builder.createQuery(BigDecimal.class);
Root<Product> productRoot = criteria.from(Product.class);
criteria.select(builder.sum(productRoot.get(Product_.someBigDecimal)));
Object sumResult = em.createQuery(criteria).getSingleResult();
assertReturnType(BigDecimal.class, sumResult);
em.getTransaction().commit();
em.close();
}
use of org.hibernate.jpa.test.metamodel.Product in project hibernate-orm by hibernate.
the class AggregationResultTest method testSumOfLongs.
/**
* Sum of Longs should return a Long
*/
@Test
public void testSumOfLongs() {
EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
CriteriaQuery<Long> criteria = builder.createQuery(Long.class);
Root<Product> productRoot = criteria.from(Product.class);
criteria.select(builder.sum(productRoot.get(Product_.partNumber)));
Object sumResult = em.createQuery(criteria).getSingleResult();
assertReturnType(Long.class, sumResult);
em.getTransaction().commit();
em.close();
}
Aggregations