Advertisement
Guest User

Untitled

a guest
Dec 8th, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.41 KB | None | 0 0
  1. Sprawozdanie:
  2.  
  3. Podczas opracowywania ostatniego zadania zauważyłem, że podczas FetchType.LAZY wykonują się dwa selecty, podczas FetchType.EAGER tylko jeden.
  4. Fetch type Eager to opozycja do Lazy, Eager załaduje wszystkie relacje od razu, lazy niestety "rozbije" proces na drobne części.
  5.  
  6. By otrzymać statementsy napisałem krótki dodatkowy test:
  7.  
  8. @Test
  9. public void testooo() {
  10.  
  11. EntityManagerFactory entityManagerFactory = Persistence.createEntityManagerFactory(ConfigConsts.PERSISTANCE_UNIT_NAME);
  12. EntityManager entityManager = entityManagerFactory.createEntityManager();
  13.  
  14. Client theClient = entityManager.find(Client.class, 1);
  15.  
  16. for (Order orders : theClient.getOrders()) {
  17. orders.getDescription();
  18. }
  19.  
  20. // EAGER - wykonuje się JEDEN select.
  21. /*
  22. *
  23. * select
  24. * client0_.id as id1_1_0_,
  25. * client0_.address as address2_1_0_,
  26. * client0_.name as name3_1_0_,
  27. * client0_.client_no as client_n4_1_0_,
  28. * client0_.ssn as ssn5_1_0_,
  29. * orders1_.CLIENT_ID as CLIENT_I5_1_1_,
  30. * orders1_.id as id1_0_1_,
  31. * orders1_.id as id1_0_2_,
  32. * orders1_.CLIENT_ID as CLIENT_I5_0_2_,
  33. * orders1_.ORDER_DATE as ORDER_DA2_0_2_,
  34. * orders1_.ORDER_DESC as ORDER_DE3_0_2_,
  35. * orders1_.ORDER_NO as ORDER_NO4_0_2_
  36. * from clients client0_
  37. * left outer join ORDERS orders1_
  38. * on client0_.id=orders1_.CLIENT_ID
  39. * where client0_.id=?
  40. *
  41. */
  42.  
  43. // LAZY - wykonują się 2x selecty.
  44.  
  45. /*
  46. * select
  47. * client0_.id as id1_1_0_,
  48. * client0_.address as address2_1_0_,
  49. * client0_.name as name3_1_0_,
  50. * client0_.client_no as client_n4_1_0_,
  51. * client0_.ssn as ssn5_1_0_
  52. * from clients client0_
  53. * where client0_.id=?
  54. *
  55. select
  56. orders0_.CLIENT_ID as CLIENT_I5_1_0_,
  57. orders0_.id as id1_0_0_,
  58. orders0_.id as id1_0_1_,
  59. orders0_.CLIENT_ID as CLIENT_I5_0_1_,
  60. orders0_.ORDER_DATE as ORDER_DA2_0_1_,
  61. orders0_.ORDER_DESC as ORDER_DE3_0_1_,
  62. orders0_.ORDER_NO as ORDER_NO4_0_1_
  63.  
  64. from ORDERS orders0_
  65. where orders0_.CLIENT_ID=?
  66. *
  67. */
  68.  
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement