Search in sources :

Example 16 with Product

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

the class ExpressionsTest method testInExplicitTupleListVarargs.

@Test
public void testInExplicitTupleListVarargs() {
    EntityManager em = getOrCreateEntityManager();
    em.getTransaction().begin();
    CriteriaQuery<Product> criteria = builder.createQuery(Product.class);
    Root<Product> from = criteria.from(Product.class);
    criteria.where(from.get(Product_.partNumber).in(((long) Integer.MAX_VALUE) + 1));
    List<Product> result = em.createQuery(criteria).getResultList();
    assertEquals(1, result.size());
    em.getTransaction().commit();
    em.close();
}
Also used : EntityManager(javax.persistence.EntityManager) Product(org.hibernate.jpa.test.metamodel.Product) Test(org.junit.Test) AbstractMetamodelSpecificTest(org.hibernate.jpa.test.metamodel.AbstractMetamodelSpecificTest)

Example 17 with Product

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

the class ExpressionsTest method testEmptyDisjunctionIsFalse.

@Test
public void testEmptyDisjunctionIsFalse() {
    EntityManager em = getOrCreateEntityManager();
    em.getTransaction().begin();
    CriteriaQuery<Product> criteria = builder.createQuery(Product.class);
    criteria.from(Product.class);
    criteria.where(builder.isFalse(builder.disjunction()));
    List<Product> result = em.createQuery(criteria).getResultList();
    assertEquals(1, result.size());
    em.getTransaction().commit();
    em.close();
}
Also used : EntityManager(javax.persistence.EntityManager) Product(org.hibernate.jpa.test.metamodel.Product) Test(org.junit.Test) AbstractMetamodelSpecificTest(org.hibernate.jpa.test.metamodel.AbstractMetamodelSpecificTest)

Example 18 with Product

use of org.hibernate.jpa.test.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();
}
Also used : EntityManager(javax.persistence.EntityManager) Product(org.hibernate.jpa.test.metamodel.Product) Test(org.junit.Test) AbstractMetamodelSpecificTest(org.hibernate.jpa.test.metamodel.AbstractMetamodelSpecificTest)

Example 19 with Product

use of org.hibernate.jpa.test.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();
}
Also used : EntityManager(javax.persistence.EntityManager) BigInteger(java.math.BigInteger) Product(org.hibernate.jpa.test.metamodel.Product) Test(org.junit.Test) AbstractMetamodelSpecificTest(org.hibernate.jpa.test.metamodel.AbstractMetamodelSpecificTest)

Example 20 with Product

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

the class AggregationResultTest method testSumOfDoubles.

/**
 * Sum of Doubles should return a Double
 */
@Test
public void testSumOfDoubles() {
    EntityManager em = getOrCreateEntityManager();
    em.getTransaction().begin();
    CriteriaQuery<Double> criteria = builder.createQuery(Double.class);
    Root<Product> productRoot = criteria.from(Product.class);
    criteria.select(builder.sum(productRoot.get(Product_.price)));
    Object sumResult = em.createQuery(criteria).getSingleResult();
    assertReturnType(Double.class, sumResult);
    em.getTransaction().commit();
    em.close();
}
Also used : EntityManager(javax.persistence.EntityManager) Product(org.hibernate.jpa.test.metamodel.Product) Test(org.junit.Test) AbstractMetamodelSpecificTest(org.hibernate.jpa.test.metamodel.AbstractMetamodelSpecificTest)

Aggregations

EntityManager (javax.persistence.EntityManager)22 Product (org.hibernate.jpa.test.metamodel.Product)22 Test (org.junit.Test)20 AbstractMetamodelSpecificTest (org.hibernate.jpa.test.metamodel.AbstractMetamodelSpecificTest)18 BigInteger (java.math.BigInteger)2 MetamodelImpl (org.hibernate.metamodel.internal.MetamodelImpl)2 CriteriaBuilderImpl (org.hibernate.query.criteria.internal.CriteriaBuilderImpl)2 TestForIssue (org.hibernate.testing.TestForIssue)2 Before (org.junit.Before)2 BigDecimal (java.math.BigDecimal)1 TypedQuery (javax.persistence.TypedQuery)1 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)1 CriteriaQuery (javax.persistence.criteria.CriteriaQuery)1 Predicate (javax.persistence.criteria.Predicate)1 Query (org.hibernate.Query)1 ComparisonPredicate (org.hibernate.query.criteria.internal.predicate.ComparisonPredicate)1 RequiresDialect (org.hibernate.testing.RequiresDialect)1 SkipForDialect (org.hibernate.testing.SkipForDialect)1