Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Sprawozdanie:
- Podczas opracowywania ostatniego zadania zauważyłem, że podczas FetchType.LAZY wykonują się dwa selecty, podczas FetchType.EAGER tylko jeden.
- Fetch type Eager to opozycja do Lazy, Eager załaduje wszystkie relacje od razu, lazy niestety "rozbije" proces na drobne części.
- By otrzymać statementsy napisałem krótki dodatkowy test:
- @Test
- public void testooo() {
- EntityManagerFactory entityManagerFactory = Persistence.createEntityManagerFactory(ConfigConsts.PERSISTANCE_UNIT_NAME);
- EntityManager entityManager = entityManagerFactory.createEntityManager();
- Client theClient = entityManager.find(Client.class, 1);
- for (Order orders : theClient.getOrders()) {
- orders.getDescription();
- }
- // EAGER - wykonuje się JEDEN select.
- /*
- *
- * select
- * client0_.id as id1_1_0_,
- * client0_.address as address2_1_0_,
- * client0_.name as name3_1_0_,
- * client0_.client_no as client_n4_1_0_,
- * client0_.ssn as ssn5_1_0_,
- * orders1_.CLIENT_ID as CLIENT_I5_1_1_,
- * orders1_.id as id1_0_1_,
- * orders1_.id as id1_0_2_,
- * orders1_.CLIENT_ID as CLIENT_I5_0_2_,
- * orders1_.ORDER_DATE as ORDER_DA2_0_2_,
- * orders1_.ORDER_DESC as ORDER_DE3_0_2_,
- * orders1_.ORDER_NO as ORDER_NO4_0_2_
- * from clients client0_
- * left outer join ORDERS orders1_
- * on client0_.id=orders1_.CLIENT_ID
- * where client0_.id=?
- *
- */
- // LAZY - wykonują się 2x selecty.
- /*
- * select
- * client0_.id as id1_1_0_,
- * client0_.address as address2_1_0_,
- * client0_.name as name3_1_0_,
- * client0_.client_no as client_n4_1_0_,
- * client0_.ssn as ssn5_1_0_
- * from clients client0_
- * where client0_.id=?
- *
- select
- orders0_.CLIENT_ID as CLIENT_I5_1_0_,
- orders0_.id as id1_0_0_,
- orders0_.id as id1_0_1_,
- orders0_.CLIENT_ID as CLIENT_I5_0_1_,
- orders0_.ORDER_DATE as ORDER_DA2_0_1_,
- orders0_.ORDER_DESC as ORDER_DE3_0_1_,
- orders0_.ORDER_NO as ORDER_NO4_0_1_
- from ORDERS orders0_
- where orders0_.CLIENT_ID=?
- *
- */
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement