The Outer-join attribute of hibernate is not simple
Source: Internet
Author: User
Lazy attribute as an important parameter of hibernate performance ... Must have been known to everyone ... Although the hibernate2.1.* does not support delay loading for the property ... However, the correct and flexible setting of the lazy attribute in Xxx-to-many can greatly improve the performance of the program.
Please take a look at the following configuration
<set name= "Moderators" lazy= "true" inverse= "false" outer-join= "true" cascade= "All" order-by= "creationdate ASC" >
<key column= "ForumID"/>
<one-to-many class= "Moderatorpo"/>
</set>
As I'm wishful thinking, this code has been used in my program for a long time, and I was once self-righteous to think that it implemented the moderators collection for me, but when I read the hibernate for my GetObject () method to output SQL ... I found out that I was getting a big list of SQL, more than 10
is the lazy setting invalid? Repeated debugging, viewing documents, Google ...
Finally, the "culprit" was found after analyzing the output of sql: Outer-join
In fact, the reason is very simple, outer-join is the external connection crawl, hibernate will separate n SQL statements through the Table_namea left join Table_nameb on (the specific syntax is determined by the actual DBMS) to merge into a single SQL submitted to the database , and return the PO object and collection's PO list, which is also an optimized measure for hibernate to improve performance and reduce database access. However, when acquiring collection, the use of Outer-join leads to the collection and PO objects themselves submitted to the query at the same time, also disguised lost the effect of delayed loading
After multiple tests when outer-join=true, your lazy property is set to any value, collection will be initially loaded (one-to-one no lazy therefore do not have to consider ^_^)
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.