use of org.hibernate.orm.test.jpa.metamodel.Product in project hibernate-orm by hibernate.
the class AggregationResultTest method testSumOfBigIntegers.
/**
* Sum of BigInteger should return a BigInteger
*/
@Test
public void testSumOfBigIntegers() {
EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
CriteriaQuery<BigInteger> criteria = builder.createQuery(BigInteger.class);
Root<Product> productRoot = criteria.from(Product.class);
criteria.select(builder.sum(productRoot.get(Product_.someBigInteger)));
Object sumResult = em.createQuery(criteria).getSingleResult();
assertReturnType(BigInteger.class, sumResult);
em.getTransaction().commit();
em.close();
}
use of org.hibernate.orm.test.jpa.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.orm.test.jpa.metamodel.Product in project hibernate-orm by hibernate.
the class AggregationResultTest method testSumOfFloats.
/**
* Sum of Floats should return a Float; note that this is distinctly different than JPAQL
*/
@Test
public void testSumOfFloats() {
EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
CriteriaQuery<Float> criteria = builder.createQuery(Float.class);
Root<Product> productRoot = criteria.from(Product.class);
criteria.select(builder.sum(productRoot.get(Product_.rating)));
Object sumResult = em.createQuery(criteria).getSingleResult();
assertReturnType(Float.class, sumResult);
em.getTransaction().commit();
em.close();
}
use of org.hibernate.orm.test.jpa.metamodel.Product in project hibernate-orm by hibernate.
the class CastTest method testCastToString.
@Test
@SkipForDialect(value = DerbyDialect.class, comment = "Derby does not support cast from INTEGER to VARCHAR")
@TestForIssue(jiraKey = "HHH-5755")
public void testCastToString(EntityManagerFactoryScope scope) {
scope.inTransaction(entityManager -> {
Product product = new Product();
product.setId("product1");
product.setPrice(1.23d);
product.setQuantity(QUANTITY);
product.setPartNumber(((long) Integer.MAX_VALUE) + 1);
product.setRating(1.999f);
product.setSomeBigInteger(BigInteger.valueOf(987654321));
product.setSomeBigDecimal(BigDecimal.valueOf(987654.321));
entityManager.persist(product);
});
scope.inTransaction(entityManager -> {
CriteriaBuilder builder = entityManager.getCriteriaBuilder();
CriteriaQuery<Product> criteria = builder.createQuery(Product.class);
Root<Product> root = criteria.from(Product.class);
criteria.where(builder.equal(root.get(Product_.quantity).as(String.class), builder.literal(String.valueOf(QUANTITY))));
List<Product> result = entityManager.createQuery(criteria).getResultList();
Assertions.assertEquals(1, result.size());
});
}
use of org.hibernate.orm.test.jpa.metamodel.Product in project hibernate-orm by hibernate.
the class ExpressionsTest method testParameterReuse.
@Test
public void testParameterReuse() {
doInJPA(this::entityManagerFactory, entityManager -> {
CriteriaQuery<Product> criteria = entityManager.getCriteriaBuilder().createQuery(Product.class);
Root<Product> from = criteria.from(Product.class);
ParameterExpression<String> param = entityManager.getCriteriaBuilder().parameter(String.class);
Predicate predicate = entityManager.getCriteriaBuilder().equal(from.get(Product_.id), param);
Predicate predicate2 = entityManager.getCriteriaBuilder().equal(from.get(Product_.name), param);
criteria.where(entityManager.getCriteriaBuilder().or(predicate, predicate2));
assertEquals(1, criteria.getParameters().size());
TypedQuery<Product> query = entityManager.createQuery(criteria);
int hqlParamCount = countGeneratedParameters(query.unwrap(Query.class));
assertEquals(1, hqlParamCount);
query.setParameter(param, "abc").getResultList();
});
}
Aggregations