Hibernate n+1 solution.
Hiberntae has n+1 problame to solve this we can use the
1) Join
2)Criteria query
========================================
Let say i have one "client " and many "product" relationship here is one to many we use but when we
try to fetch the client records it also fetch product records by default lazily.
<<<<We need to use this query for to resoled this pro blame>>>
-------------------------------------------------------------
"from Client client join fetch client.product Product"
-------------------------------------------------------------
<<<<<Hibernate will Gen rate SQL query like this.>>>>>
-------------------------------------------------------------
Select * From Client client Left Outer Join Product product ON product.product_id =client.product_id
-------------------------------------------------------------
Other way is to use Criteria Query
Criteria cr =session.createCriteria(Client.class);
cr.setFetchMode("product",FetchMode.EAGER);
Hiberntae has n+1 problame to solve this we can use the
1) Join
2)Criteria query
========================================
Let say i have one "client " and many "product" relationship here is one to many we use but when we
try to fetch the client records it also fetch product records by default lazily.
<<<<We need to use this query for to resoled this pro blame>>>
-------------------------------------------------------------
"from Client client join fetch client.product Product"
-------------------------------------------------------------
<<<<<Hibernate will Gen rate SQL query like this.>>>>>
-------------------------------------------------------------
Select * From Client client Left Outer Join Product product ON product.product_id =client.product_id
-------------------------------------------------------------
Other way is to use Criteria Query
Criteria cr =session.createCriteria(Client.class);
cr.setFetchMode("product",FetchMode.EAGER);
No comments:
Post a Comment