use of org.hibernate.orm.test.jpa.metamodel.Order in project hibernate-orm by hibernate.
the class PredicateTest method testQuotientConversion.
@Test
@TestForIssue(jiraKey = "HHH-5803")
@SkipForDialect(dialectClass = CockroachDialect.class, reason = "https://github.com/cockroachdb/cockroach/issues/41943")
public void testQuotientConversion() {
EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
CriteriaQuery<Order> orderCriteria = builder.createQuery(Order.class);
Root<Order> orderRoot = orderCriteria.from(Order.class);
Long longValue = 999999999L;
Path<Double> doublePath = orderRoot.get(Order_.totalPrice);
Path<Integer> integerPath = orderRoot.get(Order_.customer).get(Customer_.age);
orderCriteria.select(orderRoot);
Predicate p = builder.ge(builder.quot(integerPath, doublePath), longValue);
orderCriteria.where(p);
List<Order> orders = em.createQuery(orderCriteria).getResultList();
assertTrue(orders.size() == 0);
em.getTransaction().commit();
em.close();
}
use of org.hibernate.orm.test.jpa.metamodel.Order in project hibernate-orm by hibernate.
the class PredicateTest method testByteArray.
/**
* Check predicate for field which has simple byte array type (byte[]).
*/
@Test
@JiraKey("HHH-10603")
@SkipForDialect(dialectClass = OracleDialect.class, majorVersion = 12, reason = "Oracle12cDialect uses blob to store byte arrays and it's not possible to compare blobs with simple equality operators.")
public void testByteArray() {
EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
CriteriaQuery<Order> orderCriteria = builder.createQuery(Order.class);
Root<Order> orderRoot = orderCriteria.from(Order.class);
orderCriteria.select(orderRoot);
Predicate p = builder.equal(orderRoot.get("number"), new byte[] { '1', '2' });
orderCriteria.where(p);
List<Order> orders = em.createQuery(orderCriteria).getResultList();
assertTrue(orders.size() == 0);
em.getTransaction().commit();
em.close();
}
use of org.hibernate.orm.test.jpa.metamodel.Order in project hibernate-orm by hibernate.
the class CorrelatedSubqueryTest method testRestrictedCorrelationNoExplicitSelection.
@Test
public void testRestrictedCorrelationNoExplicitSelection() {
CriteriaBuilder builder = entityManagerFactory().getCriteriaBuilder();
EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
CriteriaQuery<Order> criteria = builder.createQuery(Order.class);
Root<Order> orderRoot = criteria.from(Order.class);
criteria.select(orderRoot);
// create correlated subquery
Subquery<Customer> customerSubquery = criteria.subquery(Customer.class);
Root<Order> orderRootCorrelation = customerSubquery.correlate(orderRoot);
Join<Order, Customer> orderCustomerJoin = orderRootCorrelation.join("customer");
customerSubquery.where(builder.like(orderCustomerJoin.get("name"), "%Caruso"));
criteria.where(builder.exists(customerSubquery));
em.createQuery(criteria).getResultList();
em.getTransaction().commit();
em.close();
}
use of org.hibernate.orm.test.jpa.metamodel.Order in project hibernate-orm by hibernate.
the class CorrelatedSubqueryTest method testCorrelationExplicitSelectionCorrelation.
@Test
@JiraKey("HHH-3032")
@SkipForDialect(dialectClass = SybaseASEDialect.class, majorVersion = 15)
public void testCorrelationExplicitSelectionCorrelation() {
CriteriaBuilder builder = entityManagerFactory().getCriteriaBuilder();
EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
CriteriaQuery<Customer> customerCriteria = builder.createQuery(Customer.class);
Root<Customer> customer = customerCriteria.from(Customer.class);
Join<Customer, Order> o = customer.join(Customer_.orders);
Subquery<Order> sq = customerCriteria.subquery(Order.class);
Join<Customer, Order> sqo = sq.correlate(o);
Join<Order, LineItem> sql = sqo.join(Order_.lineItems);
sq.where(builder.gt(sql.get(LineItem_.quantity), 3));
// use the correlation itself as the subquery selection (initially caused problems wrt aliases)
sq.select(sqo);
customerCriteria.select(customer).distinct(true);
customerCriteria.where(builder.exists(sq));
em.createQuery(customerCriteria).getResultList();
em.getTransaction().commit();
em.close();
}
use of org.hibernate.orm.test.jpa.metamodel.Order in project hibernate-orm by hibernate.
the class UncorrelatedSubqueryTest method testEqualAll.
@Test
public void testEqualAll() {
CriteriaBuilder builder = entityManagerFactory().getCriteriaBuilder();
EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
CriteriaQuery<Customer> criteria = builder.createQuery(Customer.class);
Root<Customer> customerRoot = criteria.from(Customer.class);
Join<Customer, Order> orderJoin = customerRoot.join(Customer_.orders);
criteria.select(customerRoot);
Subquery<Double> subCriteria = criteria.subquery(Double.class);
Root<Order> subqueryOrderRoot = subCriteria.from(Order.class);
subCriteria.select(builder.min(subqueryOrderRoot.get(Order_.totalPrice)));
criteria.where(builder.equal(orderJoin.get("totalPrice"), builder.all(subCriteria)));
em.createQuery(criteria).getResultList();
em.getTransaction().commit();
em.close();
}
Aggregations