use of org.hibernate.orm.test.jpa.metamodel.Order in project hibernate-orm by hibernate.
the class AbstractPathImplTest method testIllegalDereference.
@Test
public void testIllegalDereference() {
EntityManager em = getOrCreateEntityManager();
try {
CriteriaBuilder criteriaBuilder = em.getCriteriaBuilder();
CriteriaQuery<Order> criteria = criteriaBuilder.createQuery(Order.class);
Root<Order> orderRoot = criteria.from(Order.class);
Path simplePath = orderRoot.get("totalPrice");
// this should cause an ISE...
try {
simplePath.get("yabbadabbado");
fail("Attempt to dereference basic path should throw IllegalStateException");
} catch (IllegalStateException expected) {
}
} finally {
em.close();
}
}
use of org.hibernate.orm.test.jpa.metamodel.Order in project hibernate-orm by hibernate.
the class PredicateTest method testCharArray.
/**
* Check predicate for field which has simple char array type (char[]).
*/
@Test
public void testCharArray() {
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("domen"), new char[] { 'r', 'u' });
orderCriteria.where(p);
List<Order> orders = em.createQuery(orderCriteria).getResultList();
assertTrue(orders.size() == 1);
em.getTransaction().commit();
em.close();
}
use of org.hibernate.orm.test.jpa.metamodel.Order in project hibernate-orm by hibernate.
the class PredicateTest method testSimpleNot.
/**
* Check simple not.
*/
@Test
public void testSimpleNot() {
EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
CriteriaQuery<Order> orderCriteria = builder.createQuery(Order.class);
Root<Order> orderRoot = orderCriteria.from(Order.class);
orderCriteria.select(orderRoot);
final Predicate p = builder.not(builder.equal(orderRoot.get("id"), "order-1"));
assertEquals(Predicate.BooleanOperator.AND, p.getOperator());
orderCriteria.where(p);
List<Order> orders = em.createQuery(orderCriteria).getResultList();
assertEquals(2, orders.size());
em.getTransaction().commit();
em.close();
}
use of org.hibernate.orm.test.jpa.metamodel.Order in project hibernate-orm by hibernate.
the class PredicateTest method testComplicatedNotOr.
/**
* Check complicated not.
*/
@Test
public void testComplicatedNotOr() {
EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
CriteriaQuery<Order> orderCriteria = builder.createQuery(Order.class);
Root<Order> orderRoot = orderCriteria.from(Order.class);
orderCriteria.select(orderRoot);
Predicate p1 = builder.equal(orderRoot.get("id"), "order-1");
Predicate p2 = builder.equal(orderRoot.get("id"), "order-2");
Predicate compoundPredicate = builder.not(builder.or(p1, p2));
// negated OR should become an AND
assertEquals(Predicate.BooleanOperator.AND, compoundPredicate.getOperator());
orderCriteria.where(compoundPredicate);
List<Order> orders = em.createQuery(orderCriteria).getResultList();
assertEquals(1, orders.size());
Order order = orders.get(0);
assertEquals("order-3", order.getId());
em.getTransaction().commit();
em.close();
}
use of org.hibernate.orm.test.jpa.metamodel.Order in project hibernate-orm by hibernate.
the class PredicateTest method testEmptyConjunction.
@Test
public void testEmptyConjunction() {
EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
// yes this is a retarded case, but explicitly allowed in the JPA spec
CriteriaQuery<Order> orderCriteria = builder.createQuery(Order.class);
Root<Order> orderRoot = orderCriteria.from(Order.class);
orderCriteria.select(orderRoot);
orderCriteria.where(builder.isTrue(builder.conjunction()));
em.createQuery(orderCriteria).getResultList();
List<Order> orders = em.createQuery(orderCriteria).getResultList();
assertTrue(orders.size() == 3);
em.getTransaction().commit();
em.close();
}
Aggregations