use of org.hibernate.orm.test.jpa.metamodel.Order in project hibernate-orm by hibernate.
the class AbstractPathImplTest method testGetNonExistingAttributeViaName.
@ExpectedException(value = IllegalArgumentException.class)
@Test
public void testGetNonExistingAttributeViaName() {
EntityManager em = getOrCreateEntityManager();
try {
CriteriaBuilder criteriaBuilder = em.getCriteriaBuilder();
CriteriaQuery<Order> criteria = criteriaBuilder.createQuery(Order.class);
Root<Order> orderRoot = criteria.from(Order.class);
orderRoot.get("nonExistingAttribute");
} finally {
em.close();
}
}
use of org.hibernate.orm.test.jpa.metamodel.Order in project hibernate-orm by hibernate.
the class PredicateTest method prepareTestData.
@BeforeEach
public void prepareTestData() {
builder = entityManagerFactory().getCriteriaBuilder();
EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
em.persist(new Order("order-1", 1.0d));
em.persist(new Order("order-2", 10.0d));
em.persist(new Order("order-3", new char[] { 'r', 'u' }));
em.getTransaction().commit();
em.close();
}
use of org.hibernate.orm.test.jpa.metamodel.Order in project hibernate-orm by hibernate.
the class PredicateTest method testEmptyInPredicate.
@Test
@TestForIssue(jiraKey = "HHH-8901")
public void testEmptyInPredicate() {
EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
CriteriaQuery<Order> orderCriteria = builder.createQuery(Order.class);
Root<Order> orderRoot = orderCriteria.from(Order.class);
orderCriteria.select(orderRoot);
orderCriteria.where(builder.in(orderRoot.get("totalPrice")));
List<Order> orders = em.createQuery(orderCriteria).getResultList();
assertTrue(orders.isEmpty());
em.getTransaction().commit();
em.close();
}
use of org.hibernate.orm.test.jpa.metamodel.Order in project hibernate-orm by hibernate.
the class PredicateTest method testSimpleNot2.
/**
* Check simple not.
*/
@Test
public void testSimpleNot2() {
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.equal(orderRoot.get("id"), "order-1").not();
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 testEmptyDisjunction.
@Test
public void testEmptyDisjunction() {
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.isFalse(builder.disjunction()));
em.createQuery(orderCriteria).getResultList();
List<Order> orders = em.createQuery(orderCriteria).getResultList();
assertTrue(orders.size() == 3);
em.getTransaction().commit();
em.close();
}
Aggregations