use of org.hibernate.orm.test.jpa.metamodel.Order in project hibernate-orm by hibernate.
the class CriteriaCompilingTest method testDeprecation.
@Test
@TestForIssue(jiraKey = "HHH-10960")
public void testDeprecation() {
TransactionUtil.doInJPA(this::entityManagerFactory, entityManager -> {
Session session = entityManager.unwrap(Session.class);
CriteriaBuilder builder = session.getCriteriaBuilder();
CriteriaQuery<Order> query = builder.createQuery(Order.class);
Root<Order> from = query.from(Order.class);
query.orderBy(builder.desc(from.get("totalPrice")));
TypedQuery<Order> jpaQuery = session.createQuery(query);
Query<?> hibQuery = jpaQuery.unwrap(Query.class);
ScrollableResults sr = hibQuery.scroll(ScrollMode.FORWARD_ONLY);
hibQuery.setCacheMode(CacheMode.IGNORE).scroll(ScrollMode.FORWARD_ONLY);
Query<Order> anotherQuery = session.createQuery("select o from Order o where totalPrice in :totalPrices", Order.class);
anotherQuery.setParameterList("totalPrices", Arrays.asList(12.5d, 14.6d));
});
}
use of org.hibernate.orm.test.jpa.metamodel.Order in project hibernate-orm by hibernate.
the class UncorrelatedSubqueryTest method testGetCorrelatedParentIllegalStateException.
@Test
public void testGetCorrelatedParentIllegalStateException() {
// test that attempting to call getCorrelatedParent on a uncorrelated query/subquery
// throws ISE
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)));
assertFalse(customerRoot.isCorrelated());
assertFalse(subqueryOrderRoot.isCorrelated());
try {
customerRoot.getCorrelationParent();
fail("Should have resulted in IllegalStateException");
} catch (IllegalStateException expected) {
}
try {
subqueryOrderRoot.getCorrelationParent();
fail("Should have resulted in IllegalStateException");
} catch (IllegalStateException expected) {
}
em.getTransaction().commit();
em.close();
}
use of org.hibernate.orm.test.jpa.metamodel.Order in project hibernate-orm by hibernate.
the class CorrelatedSubqueryTest method testBasicCorrelation.
@Test
public void testBasicCorrelation() {
CriteriaBuilder builder = entityManagerFactory().getCriteriaBuilder();
EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
CriteriaQuery<Customer> criteria = builder.createQuery(Customer.class);
Root<Customer> customer = criteria.from(Customer.class);
criteria.select(customer);
Subquery<Order> orderSubquery = criteria.subquery(Order.class);
Root<Customer> customerCorrelationRoot = orderSubquery.correlate(customer);
Join<Customer, Order> customerOrderCorrelationJoin = customerCorrelationRoot.join(Customer_.orders);
orderSubquery.select(customerOrderCorrelationJoin);
criteria.where(builder.not(builder.exists(orderSubquery)));
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 testRestrictedCorrelation.
@Test
public void testRestrictedCorrelation() {
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(Order_.customer);
customerSubquery.where(builder.like(orderCustomerJoin.get(Customer_.name), "%Caruso")).select(orderCustomerJoin);
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 testCorrelatedJoinsFromSubquery.
@Test
@TestForIssue(jiraKey = "HHH-8556")
public void testCorrelatedJoinsFromSubquery() {
CriteriaBuilder builder = entityManagerFactory().getCriteriaBuilder();
CriteriaQuery<Customer> cquery = builder.createQuery(Customer.class);
Root<Customer> customer = cquery.from(Customer.class);
cquery.select(customer);
Subquery<Order> sq = cquery.subquery(Order.class);
Join<Customer, Order> sqo = sq.correlate(customer.join(Customer_.orders));
sq.select(sqo);
Set<Join<?, ?>> cJoins = sq.getCorrelatedJoins();
// ensure the join is returned in #getCorrelatedJoins
assertEquals(cJoins.size(), 1);
}
Aggregations