use of org.hibernate.jpa.test.metamodel.LineItem in project hibernate-orm by hibernate.
the class OnKeywordTest method basicTest.
@Test
public void basicTest() {
EntityManager em = getOrCreateEntityManager();
CriteriaQuery<Order> criteria = em.getCriteriaBuilder().createQuery(Order.class);
Root<Order> root = criteria.from(Order.class);
criteria.select(root);
CollectionJoin<Order, LineItem> lineItemsJoin = root.join(Order_.lineItems);
lineItemsJoin.on(em.getCriteriaBuilder().gt(lineItemsJoin.get(LineItem_.quantity), em.getCriteriaBuilder().literal(20)));
em.createQuery(criteria).getResultList();
em.close();
}
use of org.hibernate.jpa.test.metamodel.LineItem in project hibernate-orm by hibernate.
the class CorrelatedSubqueryTest method testCorrelationExplicitSelectionCorrelation.
@Test
@SkipForDialect(value = SybaseASE15Dialect.class, jiraKey = "HHH-3032")
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.jpa.test.metamodel.LineItem in project hibernate-orm by hibernate.
the class ImplicitJoinTest method testImplicitJoinFromExplicitCollectionJoin.
@Test
public void testImplicitJoinFromExplicitCollectionJoin() {
EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
CriteriaBuilder criteriaBuilder = em.getCriteriaBuilder();
CriteriaQuery<Order> criteria = criteriaBuilder.createQuery(Order.class);
Root<Order> orderRoot = criteria.from(Order.class);
Join<Order, LineItem> lineItemsJoin = orderRoot.join(Order_.lineItems);
criteria.where(criteriaBuilder.lt(lineItemsJoin.get(LineItem_.quantity), 2));
criteria.select(orderRoot).distinct(true);
TypedQuery<Order> query = em.createQuery(criteria);
query.getResultList();
em.getTransaction().commit();
em.close();
}
Aggregations