use of org.hibernate.userguide.model.Person in project hibernate-orm by hibernate.
the class HQLTest method test_hql_api_list_example.
@Test
public void test_hql_api_list_example() {
doInJPA(this::entityManagerFactory, entityManager -> {
Session session = entityManager.unwrap(Session.class);
List<Person> persons = session.createQuery("select p " + "from Person p " + "where p.name like :name").setParameter("name", "J%").list();
});
}
use of org.hibernate.userguide.model.Person in project hibernate-orm by hibernate.
the class HQLTest method test_hql_collection_expressions_example_5.
@Test
public void test_hql_collection_expressions_example_5() {
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 = some elements ( 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 HQLTest method test_hql_select_simplest_example.
@Test
public void test_hql_select_simplest_example() {
doInJPA(this::entityManagerFactory, entityManager -> {
Session session = entityManager.unwrap(Session.class);
List<Object> objects = session.createQuery("from java.lang.Object").list();
List<Person> persons = session.createQuery("from Person").list();
});
}
use of org.hibernate.userguide.model.Person in project hibernate-orm by hibernate.
the class HQLTest method test_jpql_api_named_query_example.
@Test
public void test_jpql_api_named_query_example() {
doInJPA(this::entityManagerFactory, entityManager -> {
Query query = entityManager.createNamedQuery("get_person_by_name");
TypedQuery<Person> typedQuery = entityManager.createNamedQuery("get_person_by_name", Person.class);
});
}
use of org.hibernate.userguide.model.Person in project hibernate-orm by hibernate.
the class MySQLStoredProcedureTest method init.
@Before
public void init() {
destroy();
doInJPA(this::entityManagerFactory, entityManager -> {
Session session = entityManager.unwrap(Session.class);
session.doWork(connection -> {
try (Statement statement = connection.createStatement()) {
statement.executeUpdate("CREATE PROCEDURE sp_count_phones (" + " IN personId INT, " + " OUT phoneCount INT " + ") " + "BEGIN " + " SELECT COUNT(*) INTO phoneCount " + " FROM Phone p " + " WHERE p.person_id = personId; " + "END");
statement.executeUpdate("CREATE PROCEDURE sp_phones(IN personId INT) " + "BEGIN " + " SELECT * " + " FROM Phone " + " WHERE person_id = personId; " + "END");
statement.executeUpdate("CREATE FUNCTION fn_count_phones(personId integer) " + "RETURNS integer " + "DETERMINISTIC " + "READS SQL DATA " + "BEGIN " + " DECLARE phoneCount integer; " + " SELECT COUNT(*) INTO phoneCount " + " FROM Phone p " + " WHERE p.person_id = personId; " + " RETURN phoneCount; " + "END");
}
});
});
doInJPA(this::entityManagerFactory, entityManager -> {
Person person1 = new Person("John Doe");
person1.setNickName("JD");
person1.setAddress("Earth");
person1.setCreatedOn(Timestamp.from(LocalDateTime.of(2000, 1, 1, 0, 0, 0).toInstant(ZoneOffset.UTC)));
person1.getAddresses().put(AddressType.HOME, "Home address");
person1.getAddresses().put(AddressType.OFFICE, "Office address");
entityManager.persist(person1);
Phone phone1 = new Phone("123-456-7890");
phone1.setId(1L);
phone1.setType(PhoneType.MOBILE);
person1.addPhone(phone1);
Phone phone2 = new Phone("098_765-4321");
phone2.setId(2L);
phone2.setType(PhoneType.LAND_LINE);
person1.addPhone(phone2);
});
}
Aggregations