hibernatejoinfetch
TRANSCRIPT
![Page 1: Hibernatejoinfetch](https://reader036.vdocuments.us/reader036/viewer/2022081401/558714c6d8b42add508b4694/html5/thumbnails/1.jpg)
1
Hibernate Fetch Strategies,Hibernate Fetch Strategies,N+1 Select ProblemN+1 Select Problem
![Page 2: Hibernatejoinfetch](https://reader036.vdocuments.us/reader036/viewer/2022081401/558714c6d8b42add508b4694/html5/thumbnails/2.jpg)
2
Topics
● Fetching strategies● Types of fetching strategies– How fetching is done– When fetching is done
● N+1 select problem– Factors that influence number of select statements– Various examples
● Recommendation
![Page 3: Hibernatejoinfetch](https://reader036.vdocuments.us/reader036/viewer/2022081401/558714c6d8b42add508b4694/html5/thumbnails/3.jpg)
3
Fetching StrategiesFetching Strategies
![Page 4: Hibernatejoinfetch](https://reader036.vdocuments.us/reader036/viewer/2022081401/558714c6d8b42add508b4694/html5/thumbnails/4.jpg)
4
What is a Fetching Strategy?
● A fetching strategy is the strategy Hibernate will use for retrieving associated objects if the application needs to navigate the association.
● Fetching strategy will have performance impact● Fetch strategies may be declared in the
mapping files, or over-ridden by a particular HQL or Criteria query.
![Page 5: Hibernatejoinfetch](https://reader036.vdocuments.us/reader036/viewer/2022081401/558714c6d8b42add508b4694/html5/thumbnails/5.jpg)
5
Types of Fetching Strategies
● How fetching is done– Join– Select (default)– Subselect– Batch
● When fetching is done– immediate– lazy (default)
![Page 6: Hibernatejoinfetch](https://reader036.vdocuments.us/reader036/viewer/2022081401/558714c6d8b42add508b4694/html5/thumbnails/6.jpg)
6
Fetching Strategies:Fetching Strategies:How Fetching is DoneHow Fetching is Done
![Page 7: Hibernatejoinfetch](https://reader036.vdocuments.us/reader036/viewer/2022081401/558714c6d8b42add508b4694/html5/thumbnails/7.jpg)
7
Join Fetching
● Hibernate retrieves the associated instance or collection in the same SELECT, using an OUTER JOIN
![Page 8: Hibernatejoinfetch](https://reader036.vdocuments.us/reader036/viewer/2022081401/558714c6d8b42add508b4694/html5/thumbnails/8.jpg)
8
Join Fetching in HQL
String hql = "from Product p join fetch p.supplier as s";Query query = session.createQuery(hql);List results = query.list();
![Page 9: Hibernatejoinfetch](https://reader036.vdocuments.us/reader036/viewer/2022081401/558714c6d8b42add508b4694/html5/thumbnails/9.jpg)
9
Join Fetching in Criteria API
Criteria crit = session.createCriteria(Product.class);crit.setFetchMode("supplier", FetchMode.JOIN);List results = crit.list();
![Page 10: Hibernatejoinfetch](https://reader036.vdocuments.us/reader036/viewer/2022081401/558714c6d8b42add508b4694/html5/thumbnails/10.jpg)
10
Select Fetching
● Default fetch mode● Vulnerable to N+1 selects problem– “N” number of SELECT's are used to retrieve the
associated entity or collection.● Unless you explicitly disable lazy fetching by
specifying lazy="false", the subsequent select will only be executed when you actually access the association.
![Page 11: Hibernatejoinfetch](https://reader036.vdocuments.us/reader036/viewer/2022081401/558714c6d8b42add508b4694/html5/thumbnails/11.jpg)
11
Subselect Fetching
● A second SELECT is used to retrieve the associated collections for all entities retrieved in a previous query or fetch.
● Unless you explicitly disable lazy fetching by specifying lazy="false", this second select will only be executed when you actually access the association.
![Page 12: Hibernatejoinfetch](https://reader036.vdocuments.us/reader036/viewer/2022081401/558714c6d8b42add508b4694/html5/thumbnails/12.jpg)
12
Batch Fetching
● An optimization strategy for select fetching - Hibernate retrieves a batch of entity instances or collections in a single SELECT, by specifying a list of primary keys or foreign keys.
![Page 13: Hibernatejoinfetch](https://reader036.vdocuments.us/reader036/viewer/2022081401/558714c6d8b42add508b4694/html5/thumbnails/13.jpg)
13
Tuning fetch strategies
● Select fetching (the default) is extremely vulnerable to N+1 selects problems, so you might want to enable join fetching in the mapping document:
<set name="permissions" fetch="join"> <key column="userId"/> <one-to-many class="Permission"/></set
![Page 14: Hibernatejoinfetch](https://reader036.vdocuments.us/reader036/viewer/2022081401/558714c6d8b42add508b4694/html5/thumbnails/14.jpg)
14
Fetching Strategies:Fetching Strategies:When Fetching is DoneWhen Fetching is Done
![Page 15: Hibernatejoinfetch](https://reader036.vdocuments.us/reader036/viewer/2022081401/558714c6d8b42add508b4694/html5/thumbnails/15.jpg)
15
Lazy Fetching
● A collection is fetched when the application invokes an operation upon that collection
● Default for collections
![Page 16: Hibernatejoinfetch](https://reader036.vdocuments.us/reader036/viewer/2022081401/558714c6d8b42add508b4694/html5/thumbnails/16.jpg)
16
N+1 SelectN+1 SelectProblem Problem
![Page 17: Hibernatejoinfetch](https://reader036.vdocuments.us/reader036/viewer/2022081401/558714c6d8b42add508b4694/html5/thumbnails/17.jpg)
17
Example Scenario● Supplier with a one-to-many relationship with
Product. – One Supplier has (supplies) many Products
![Page 18: Hibernatejoinfetch](https://reader036.vdocuments.us/reader036/viewer/2022081401/558714c6d8b42add508b4694/html5/thumbnails/18.jpg)
18
Example Data
******** Table: Supplier *******+-------------+----------------------+| ID | NAME |+-------------+----------------------+| 1 | Supplier Name 1 || 2 | Supplier Name 2 || 3 | Supplier Name 3 || 4 | Supplier Name 4 |+-------------+----------------------+
******** Table: Product *******+-------------+----------------------+--------------------------------+------------------------+--------------------+| ID | NAME | DESCRIPTION | PRICE | SUPPLIERID |+-------------+----------------------+--------------------------------+------------------------+--------------------+| 1 | Product 1 | Name for Product 1 | 2.0 | 1 || 2 | Product 2 | Name for Product 2 | 22.0 | 1 || 3 | Product 3 | Name for Product 3 | 30.0 | 2 || 4 | Product 4 | Name for Product 4 | 7.0 | 3 |+-------------+----------------------+--------------------------------+------------------------+--------------------+
![Page 19: Hibernatejoinfetch](https://reader036.vdocuments.us/reader036/viewer/2022081401/558714c6d8b42add508b4694/html5/thumbnails/19.jpg)
19
Factors that influence “number of select statements”● When fetching is done– lazy mode for Supplier
● How fetching is done– Fetch mode used for querying on Product– Select vs. Join
● Whether Supplier is accessed through Product or not
● Caching– Whether Supplier is cached or now
![Page 20: Hibernatejoinfetch](https://reader036.vdocuments.us/reader036/viewer/2022081401/558714c6d8b42add508b4694/html5/thumbnails/20.jpg)
20
Hands-on Lab Exercises
1.LazyTrue-SelectFetch-SupplierNotAccessed2.LazyTrue-SelectFetch-SupplierAccessed3.LazyFalse-SelectFetch-SupplierNotAccessed4.LazyFalse-SelectFetch-SupplierAccessed5.LazyTrue-JoinFetch-SupplierNotAccessed6.LazyTrue-JoinFetch-SupplierAccessed7.LazyFalse-JoinFetch-SupplierNotAccessed8.LazyFalse-JoinFetch-SupplierAccessed
![Page 21: Hibernatejoinfetch](https://reader036.vdocuments.us/reader036/viewer/2022081401/558714c6d8b42add508b4694/html5/thumbnails/21.jpg)
21
Hands-on Lab Exercises
9.LazyFalse-JoinFetchLeftOuter-SupplierAccessed10.LazyFalse-JoinFetchRightOuter-SupplierAccessed
![Page 22: Hibernatejoinfetch](https://reader036.vdocuments.us/reader036/viewer/2022081401/558714c6d8b42add508b4694/html5/thumbnails/22.jpg)
22
Example #1Example #1LazyTrue-SelectFetch-LazyTrue-SelectFetch-SupplierNotAccessedSupplierNotAccessed
![Page 23: Hibernatejoinfetch](https://reader036.vdocuments.us/reader036/viewer/2022081401/558714c6d8b42add508b4694/html5/thumbnails/23.jpg)
23
Example #1● Factors – lazy mode for Supplier set to “true” (default)– Fetch mode used for querying on Product is Select
fetch mode (default) – Supplier information is not accessed – Caching does not play a role for the first time the
Supplier is accessed● Sample project in the hands-on lab– 01HibernateHQLQuery-LazyTrue-SelectFetch-
SupplierNotAccessed
![Page 24: Hibernatejoinfetch](https://reader036.vdocuments.us/reader036/viewer/2022081401/558714c6d8b42add508b4694/html5/thumbnails/24.jpg)
24
Supplier.hbm.xml: lazy=”true”<hibernate-mapping> <!-- lazy attribute is not set so it takes the default value of true --> <class name="Supplier"> <id name="id" type="int"> <generator class="increment"/> </id>
<property name="name" type="string"/> <bag name="products" inverse="true" cascade="all,delete-
orphan"> <key column="supplierId"/> <one-to-many class="Product"/> </bag>
</class></hibernate-mapping>
![Page 25: Hibernatejoinfetch](https://reader036.vdocuments.us/reader036/viewer/2022081401/558714c6d8b42add508b4694/html5/thumbnails/25.jpg)
25
Fetch mode is Select Fetch (default)
// It takes Select fetch mode as a defaultQuery query = session.createQuery( "from Product p");List list = query.list();
// Supplier is not being accesseddisplayProductsListWithoutSupplierName(results);
![Page 26: Hibernatejoinfetch](https://reader036.vdocuments.us/reader036/viewer/2022081401/558714c6d8b42add508b4694/html5/thumbnails/26.jpg)
26
Supplier is not accessedpublic static void displayProductsListWithoutSupplierName(List list){ Iterator iter = list.iterator(); if (!iter.hasNext()){ System.out.println("No products to display."); return; } while (iter.hasNext()){ Product product = (Product) iter.next(); // String msg = product.getSupplier().getName() + "\t"; String msg = "\t"; msg += product.getName() + "\t"; msg += product.getPrice() + "\t"; msg += product.getDescription(); System.out.println(msg); } }
![Page 27: Hibernatejoinfetch](https://reader036.vdocuments.us/reader036/viewer/2022081401/558714c6d8b42add508b4694/html5/thumbnails/27.jpg)
27
Number of Select Statements select ... various field names ... from PRODUCT
● 1 select statement for Product● Delayed N+1 select problem, however, since
Supplier is not accessed for now
![Page 28: Hibernatejoinfetch](https://reader036.vdocuments.us/reader036/viewer/2022081401/558714c6d8b42add508b4694/html5/thumbnails/28.jpg)
28
Example #2Example #2LazyTrue-SelectFetch-LazyTrue-SelectFetch-
SupplierAccessedSupplierAccessed
![Page 29: Hibernatejoinfetch](https://reader036.vdocuments.us/reader036/viewer/2022081401/558714c6d8b42add508b4694/html5/thumbnails/29.jpg)
29
Example #2● Factors – lazy mode for Supplier set to “true” (default)– Fetch mode used for querying on Product is Select
fetch mode (default) – Supplier information is accessed – Caching does not play a role for the first time the
Supplier is accessed● Sample project in the hands-on lab– 02HibernateHQLQuery-LazyTrue-SelectFetch-
SupplierAccessed
![Page 30: Hibernatejoinfetch](https://reader036.vdocuments.us/reader036/viewer/2022081401/558714c6d8b42add508b4694/html5/thumbnails/30.jpg)
30
Fetch mode is Select Fetch (default)
// It takes Select fetch mode as a defaultQuery query = session.createQuery( "from Product p");List list = query.list();
// Supplier is being accesseddisplayProductsListWithSupplierName(results);
![Page 31: Hibernatejoinfetch](https://reader036.vdocuments.us/reader036/viewer/2022081401/558714c6d8b42add508b4694/html5/thumbnails/31.jpg)
31
Supplier is accessedpublic static void displayProductsListWithSupplierName(List list){ Iterator iter = list.iterator(); if (!iter.hasNext()){ System.out.println("No products to display."); return; } while (iter.hasNext()){ Product product = (Product) iter.next(); String msg = product.getSupplier().getName() + "\t"; String msg = "\t"; msg += product.getName() + "\t"; msg += product.getPrice() + "\t"; msg += product.getDescription(); System.out.println(msg); } }
![Page 32: Hibernatejoinfetch](https://reader036.vdocuments.us/reader036/viewer/2022081401/558714c6d8b42add508b4694/html5/thumbnails/32.jpg)
32
Select Statements Used
select ... various field names ... from PRODUCTselect ... various field names ... from SUPPLIER where SUPPLIER.id=?select ... various field names ... from SUPPLIER where SUPPLIER.id=?select ... various field names ... from SUPPLIER where SUPPLIER.id=?
● Result – 1 select statement for Product– N select statements for Supplier
● This is N+1 select problem!
![Page 33: Hibernatejoinfetch](https://reader036.vdocuments.us/reader036/viewer/2022081401/558714c6d8b42add508b4694/html5/thumbnails/33.jpg)
33
Example #3Example #3LazyFalse-SelectFetch-LazyFalse-SelectFetch-
SupplierAccessedSupplierAccessed
![Page 34: Hibernatejoinfetch](https://reader036.vdocuments.us/reader036/viewer/2022081401/558714c6d8b42add508b4694/html5/thumbnails/34.jpg)
34
Example Scenario #3● Factors – lazy mode for Supplier set to “false” – Fetch mode used for querying on Product is Select
fetch mode (default) – Supplier information is not accessed – Caching does not play a role for the first time the
Supplier is accessed● Sample project in the hands-on lab– 03HibernateHQLQuery-LazyFase-SelectFetch-
SupplierNotAccessed
![Page 35: Hibernatejoinfetch](https://reader036.vdocuments.us/reader036/viewer/2022081401/558714c6d8b42add508b4694/html5/thumbnails/35.jpg)
35
Supplier.hbm.xml: lazy=”false”<hibernate-mapping> <class name="Supplier" lazy="false"> <id name="id" type="int"> <generator class="increment"/> </id>
<property name="name" type="string"/> <bag name="products" inverse="true" cascade="all,delete-
orphan"> <key column="supplierId"/> <one-to-many class="Product"/> </bag>
</class></hibernate-mapping>
![Page 36: Hibernatejoinfetch](https://reader036.vdocuments.us/reader036/viewer/2022081401/558714c6d8b42add508b4694/html5/thumbnails/36.jpg)
36
Fetch mode is Select Fetch (default)
// It takes Select fetch mode as a defaultQuery query = session.createQuery( "from Product p");List list = query.list();
// Supplier is not being accesseddisplayProductsListWithoutSupplierName(results);
![Page 37: Hibernatejoinfetch](https://reader036.vdocuments.us/reader036/viewer/2022081401/558714c6d8b42add508b4694/html5/thumbnails/37.jpg)
37
Select Statements Used select ... various field names ... from PRODUCTselect ... various field names ... from SUPPLIER where SUPPLIER.id=?select ... various field names ... from SUPPLIER where SUPPLIER.id=?select ... various field names ... from SUPPLIER where SUPPLIER.id=?
● Result – 1 select statement for Product– N select statements for Supplier
● This is N+1 select problem! – Even though Supplier is not accessed, because lazy is
set to false, N select statements are used to access Supplier
![Page 38: Hibernatejoinfetch](https://reader036.vdocuments.us/reader036/viewer/2022081401/558714c6d8b42add508b4694/html5/thumbnails/38.jpg)
38
Example #4Example #4LazyFalse-SelectFetch-LazyFalse-SelectFetch-SupplierNotAccessedSupplierNotAccessed
![Page 39: Hibernatejoinfetch](https://reader036.vdocuments.us/reader036/viewer/2022081401/558714c6d8b42add508b4694/html5/thumbnails/39.jpg)
39
Example Scenario #4● Factors – lazy mode for Supplier set to “false” – Fetch mode used for querying on Product is Select
fetch mode (default) – Supplier information is accessed – Caching does not play a role for the first time the
Supplier is accessed● Sample project in the hands-on lab– 04HibernateHQLQuery-LazyFase-SelectFetch-
SupplierAccessed
![Page 40: Hibernatejoinfetch](https://reader036.vdocuments.us/reader036/viewer/2022081401/558714c6d8b42add508b4694/html5/thumbnails/40.jpg)
40
Select Statements Used select ... various field names ... from PRODUCTselect ... various field names ... from SUPPLIER where SUPPLIER.id=?select ... various field names ... from SUPPLIER where SUPPLIER.id=?select ... various field names ... from SUPPLIER where SUPPLIER.id=?
● Result – 1 select statement for Product– N select statements for Supplier
● This is N+1 select problem! – Even though Supplier is not accessed, because lazy is
set to false, N select statements are used to access Supplier
![Page 41: Hibernatejoinfetch](https://reader036.vdocuments.us/reader036/viewer/2022081401/558714c6d8b42add508b4694/html5/thumbnails/41.jpg)
41
Example #5Example #5LazyTrue-JoinFetch-LazyTrue-JoinFetch-
SupplierNotAccessedSupplierNotAccessed
![Page 42: Hibernatejoinfetch](https://reader036.vdocuments.us/reader036/viewer/2022081401/558714c6d8b42add508b4694/html5/thumbnails/42.jpg)
42
Example #5● Factors – lazy mode for Supplier set to “true” (default)– Fetch mode used for querying on Product is Join fetch
mode– Supplier information is not accessed – Caching does not play a role for the first time the
Supplier is accessed● Sample project in the hands-on lab– 05HibernateHQLQuery-LazyTrue-JoinFetch-
SupplierNotAccessed
![Page 43: Hibernatejoinfetch](https://reader036.vdocuments.us/reader036/viewer/2022081401/558714c6d8b42add508b4694/html5/thumbnails/43.jpg)
43
Fetch mode is Join Fetch
// Perform Join FetchString hql = "from Product p join fetch p.supplier as s";Query query = session.createQuery(hql);List results = query.list();
// Supplier is not being accesseddisplayProductsListWithoutSupplierName(results);
![Page 44: Hibernatejoinfetch](https://reader036.vdocuments.us/reader036/viewer/2022081401/558714c6d8b42add508b4694/html5/thumbnails/44.jpg)
44
Number of Select Statements
select ... various field names from Product product0_ inner join Supplier supplier1_ on product0_.supplierId=supplier1_.id
● 1 inner join select statement● No N+1 select problem
![Page 45: Hibernatejoinfetch](https://reader036.vdocuments.us/reader036/viewer/2022081401/558714c6d8b42add508b4694/html5/thumbnails/45.jpg)
45
Example #6Example #6LazyTrue-JoinFetch-LazyTrue-JoinFetch-SupplierAccessedSupplierAccessed
![Page 46: Hibernatejoinfetch](https://reader036.vdocuments.us/reader036/viewer/2022081401/558714c6d8b42add508b4694/html5/thumbnails/46.jpg)
46
Example #6● Factors – lazy mode for Supplier set to “true” (default)– Fetch mode used for querying on Product is Join fetch
mode– Supplier information is accessed – Caching does not play a role for the first time the
Supplier is accessed● Sample project in the hands-on lab– 06HibernateHQLQuery-LazyTrue-JoinFetch-
SupplierAccessed
![Page 47: Hibernatejoinfetch](https://reader036.vdocuments.us/reader036/viewer/2022081401/558714c6d8b42add508b4694/html5/thumbnails/47.jpg)
47
Fetch mode is Join Fetch
// Perform Join FetchString hql = "from Product p join fetch p.supplier as s";Query query = session.createQuery(hql);List results = query.list();
// Supplier is being accesseddisplayProductsListWithSupplierName(results);
![Page 48: Hibernatejoinfetch](https://reader036.vdocuments.us/reader036/viewer/2022081401/558714c6d8b42add508b4694/html5/thumbnails/48.jpg)
48
Number of Select Statements
select ... various field names from Product product0_ inner join Supplier supplier1_ on product0_.supplierId=supplier1_.id
● 1 inner join select statement● No N+1 select problem
![Page 49: Hibernatejoinfetch](https://reader036.vdocuments.us/reader036/viewer/2022081401/558714c6d8b42add508b4694/html5/thumbnails/49.jpg)
49
Example #7Example #7LazyFalse-JoinFetch-LazyFalse-JoinFetch-SupplierNotAccessedSupplierNotAccessed
![Page 50: Hibernatejoinfetch](https://reader036.vdocuments.us/reader036/viewer/2022081401/558714c6d8b42add508b4694/html5/thumbnails/50.jpg)
50
Example #7● Factors – lazy mode for Supplier set to “false” – Fetch mode used for querying on Product is Join fetch
mode– Supplier information is not accessed – Caching does not play a role for the first time the
Supplier is accessed● Sample project in the hands-on lab– 07HibernateHQLQuery-LazyFalse-JoinFetch-
SupplierNotAccessed
![Page 51: Hibernatejoinfetch](https://reader036.vdocuments.us/reader036/viewer/2022081401/558714c6d8b42add508b4694/html5/thumbnails/51.jpg)
51
Number of Select Statements
select ... various field names from Product product0_ inner join Supplier supplier1_ on product0_.supplierId=supplier1_.id
● 1 inner join select statement● No N+1 select problem
![Page 52: Hibernatejoinfetch](https://reader036.vdocuments.us/reader036/viewer/2022081401/558714c6d8b42add508b4694/html5/thumbnails/52.jpg)
52
Example #8Example #8LazyFalse-JoinFetch-LazyFalse-JoinFetch-
SupplierAccessedSupplierAccessed
![Page 53: Hibernatejoinfetch](https://reader036.vdocuments.us/reader036/viewer/2022081401/558714c6d8b42add508b4694/html5/thumbnails/53.jpg)
53
Example #8● Factors – lazy mode for Supplier set to “false” – Fetch mode used for querying on Product is Join fetch
mode– Supplier information is accessed – Caching does not play a role for the first time the
Supplier is accessed● Sample project in the hands-on lab– 08HibernateHQLQuery-LazyFalse-JoinFetch-
SupplierAccessed
![Page 54: Hibernatejoinfetch](https://reader036.vdocuments.us/reader036/viewer/2022081401/558714c6d8b42add508b4694/html5/thumbnails/54.jpg)
54
Number of Select Statements
select ... various field names from Product product0_ inner join Supplier supplier1_ on product0_.supplierId=supplier1_.id
● 1 inner join select statement● No N+1 select problem
![Page 55: Hibernatejoinfetch](https://reader036.vdocuments.us/reader036/viewer/2022081401/558714c6d8b42add508b4694/html5/thumbnails/55.jpg)
55
Example #9Example #9LazyTrue-SelectFetch-LazyTrue-SelectFetch-
SupplierAccessed-CachingSupplierAccessed-Caching
![Page 56: Hibernatejoinfetch](https://reader036.vdocuments.us/reader036/viewer/2022081401/558714c6d8b42add508b4694/html5/thumbnails/56.jpg)
56
Example #2● Factors – lazy mode for Supplier set to “true” (default)– Fetch mode used for querying on Product is Select
fetch mode (default) – Supplier information is accessed – Caching play a role the Supplier is accessed the
second time● Sample project in the hands-on lab– HibernateHQLQuery-LazyTrue-SelectFetch-
SupplierAccessed-Caching
![Page 57: Hibernatejoinfetch](https://reader036.vdocuments.us/reader036/viewer/2022081401/558714c6d8b42add508b4694/html5/thumbnails/57.jpg)
57
Access Supplier Through Cache System.out.println("\n---Performing HQL query with LazyTrue-SelectFetch-SupplierAccessed..."); Query query = session.createQuery("from Product"); List results = query.list(); displayProductsListWithSupplierName(results);
System.out.println("\n---Performing HQL query using Cache..."); Query query = session.createQuery("from Product"); List results = query.list(); displayProductsListWithSupplierName(results);
// Clear cache session.clear(); System.out.println("\n---Performing HQL query after clearing Cache..."); Query query = session.createQuery("from Product"); List results = query.list(); displayProductsListWithSupplierName(results);
![Page 58: Hibernatejoinfetch](https://reader036.vdocuments.us/reader036/viewer/2022081401/558714c6d8b42add508b4694/html5/thumbnails/58.jpg)
58
Select Statements Used select ... various field names ... from PRODUCTselect ... various field names ... from SUPPLIER where SUPPLIER.id=?select ... various field names ... from SUPPLIER where SUPPLIER.id=?select ... various field names ... from SUPPLIER where SUPPLIER.id=?
select ... various field names ... from PRODUCT
select ... various field names ... from PRODUCTselect ... various field names ... from SUPPLIER where SUPPLIER.id=?select ... various field names ... from SUPPLIER where SUPPLIER.id=?select ... various field names ... from SUPPLIER where SUPPLIER.id=?
![Page 59: Hibernatejoinfetch](https://reader036.vdocuments.us/reader036/viewer/2022081401/558714c6d8b42add508b4694/html5/thumbnails/59.jpg)
59
Fetching Strategies:Fetching Strategies:RecommendationsRecommendations
![Page 60: Hibernatejoinfetch](https://reader036.vdocuments.us/reader036/viewer/2022081401/558714c6d8b42add508b4694/html5/thumbnails/60.jpg)
60
Recommendation● Join fetching is good for small collection of child
objects often used with parent● Large collections and/or not always used
collections are better retrieved with lazy select fetching
![Page 61: Hibernatejoinfetch](https://reader036.vdocuments.us/reader036/viewer/2022081401/558714c6d8b42add508b4694/html5/thumbnails/61.jpg)
61
Hibernate Fetch Strategies,Hibernate Fetch Strategies,N+1 Select ProblemN+1 Select Problem