use of org.hibernate.userguide.model.Person in project hibernate-orm by hibernate.
the class HQLTest method test_hql_collection_expressions_example_4.
@Test
public void test_hql_collection_expressions_example_4() {
doInJPA(this::entityManagerFactory, entityManager -> {
Call call = entityManager.createQuery("select c from Call c", Call.class).getResultList().get(0);
Phone phone = call.getPhone();
List<Person> persons = entityManager.createQuery("select p " + "from Person p " + "where :phone member of p.phones", Person.class).setParameter("phone", phone).getResultList();
assertEquals(1, persons.size());
});
}
use of org.hibernate.userguide.model.Person in project hibernate-orm by hibernate.
the class CriteriaTest method test_criteria_from_multiple_root_example.
@Test
public void test_criteria_from_multiple_root_example() {
doInJPA(this::entityManagerFactory, entityManager -> {
String address = "Earth";
String prefix = "J%";
CriteriaBuilder builder = entityManager.getCriteriaBuilder();
CriteriaQuery<Tuple> criteria = builder.createQuery(Tuple.class);
Root<Person> personRoot = criteria.from(Person.class);
Root<Partner> partnerRoot = criteria.from(Partner.class);
criteria.multiselect(personRoot, partnerRoot);
Predicate personRestriction = builder.and(builder.equal(personRoot.get(Person_.address), address), builder.isNotEmpty(personRoot.get(Person_.phones)));
Predicate partnerRestriction = builder.and(builder.like(partnerRoot.get(Partner_.name), prefix), builder.equal(partnerRoot.get(Partner_.version), 0));
criteria.where(builder.and(personRestriction, partnerRestriction));
List<Tuple> tuples = entityManager.createQuery(criteria).getResultList();
assertEquals(2, tuples.size());
});
}
use of org.hibernate.userguide.model.Person 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 org.hibernate.userguide.model.Person 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 org.hibernate.userguide.model.Person 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);
});
}
Aggregations