use of javax.persistence.criteria.CriteriaBuilder in project hibernate-orm by hibernate.
the class CriteriaTest method test_criteria_typedquery_multiselect_explicit_array_example.
@Test
public void test_criteria_typedquery_multiselect_explicit_array_example() {
doInJPA(this::entityManagerFactory, entityManager -> {
CriteriaBuilder builder = entityManager.getCriteriaBuilder();
CriteriaQuery<Object[]> criteria = builder.createQuery(Object[].class);
Root<Person> root = criteria.from(Person.class);
Path<Long> idPath = root.get(Person_.id);
Path<String> nickNamePath = root.get(Person_.nickName);
criteria.select(builder.array(idPath, nickNamePath));
criteria.where(builder.equal(root.get(Person_.name), "John Doe"));
List<Object[]> idAndNickNames = entityManager.createQuery(criteria).getResultList();
assertEquals(1, idAndNickNames.size());
});
}
use of javax.persistence.criteria.CriteriaBuilder in project hibernate-orm by hibernate.
the class CriteriaTest method test_criteria_param_example.
@Test
public void test_criteria_param_example() {
doInJPA(this::entityManagerFactory, entityManager -> {
CriteriaBuilder builder = entityManager.getCriteriaBuilder();
CriteriaQuery<Person> criteria = builder.createQuery(Person.class);
Root<Person> root = criteria.from(Person.class);
ParameterExpression<String> nickNameParameter = builder.parameter(String.class);
criteria.where(builder.equal(root.get(Person_.nickName), nickNameParameter));
TypedQuery<Person> query = entityManager.createQuery(criteria);
query.setParameter(nickNameParameter, "JD");
List<Person> persons = query.getResultList();
assertEquals(1, persons.size());
});
}
use of javax.persistence.criteria.CriteriaBuilder in project hibernate-orm by hibernate.
the class CriteriaTest method test_criteria_from_root_example.
@Test
public void test_criteria_from_root_example() {
doInJPA(this::entityManagerFactory, entityManager -> {
CriteriaBuilder builder = entityManager.getCriteriaBuilder();
CriteriaQuery<Person> criteria = builder.createQuery(Person.class);
Root<Person> root = criteria.from(Person.class);
});
}
use of javax.persistence.criteria.CriteriaBuilder in project hibernate-orm by hibernate.
the class QueryBuilderTest method testMissingDialectFunction.
@Test
@TestForIssue(jiraKey = "HHH-10737")
@FailureExpected(jiraKey = "HHH-10737")
public void testMissingDialectFunction() {
doInJPA(this::entityManagerFactory, em -> {
Human human = new Human();
human.setId(200L);
human.setName("2");
human.setBorn(new Date());
em.persist(human);
em.getTransaction().commit();
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<HumanDTO> criteria = cb.createQuery(HumanDTO.class);
Root<Human> root = criteria.from(Human.class);
criteria.select(cb.construct(HumanDTO.class, root.get(Human_.id), root.get(Human_.name), cb.function("convert", String.class, root.get(Human_.born), cb.literal(110))));
em.createQuery(criteria).getResultList();
});
}
use of javax.persistence.criteria.CriteriaBuilder in project hibernate-orm by hibernate.
the class TreatJoinTest method testTreatJoin2.
@Test
@TestForIssue(jiraKey = "HHH-8488")
public void testTreatJoin2() {
doInJPA(this::entityManagerFactory, entityManager -> {
CriteriaBuilder cb = entityManager.getCriteriaBuilder();
CriteriaQuery<Bid> query = cb.createQuery(Bid.class);
Root<Bid> bid = query.from(Bid.class);
cb.treat(bid.join("item"), Book.class);
cb.treat(bid.join("item"), Car.class);
query.select(bid);
final List<Bid> resultList = entityManager.createQuery(query).getResultList();
assertThat(resultList.size(), is(2));
});
}
Aggregations