Proxy no-proxy of lazy in hibernate

Source: Internet
Author: User

 

For example:
Child <-parent-to-one-> parent

Class child {
Private parent;

Public parent getparent (){
Return this. parent; // The instance variable is accessed.
}

}

Class Parent {
Private string name;

Public String getname (){
Return this. Name; // The instance variable is accessed.
}

Public void F (){
System. Out. println ("invokeing F ()"); // no instance variable is accessed
}
}

If the role-to-one lazy is set to proxy. getparent (). getname () or child. getparent (). F (), the parent will be crawled. If it is set to no-proxy, the child. getparent (). when F () is used, the parent is not captured, and this method requires enhanced bytecode during compilation. Otherwise, it is no different from the proxy. (Note: The test shows that it is the same as the proxy and cannot understand the bytecode enhancement during compilation. Where can I modify it or what conditions ?)

If lazy = "proxy" is set, the associated parent is called through child. If any method defined in the parent class is called, parent will be crawled (is the so-called capture performed by querying from the database and executing a SELECT statement ?)
If lazy = "no-proxy" is set, the parent will be captured only when the method of the class variable involved in the parent class is called. Otherwise, it will be like calling F () and will not capture the parent.

What does "bytecode enhancement during compilation" mean?
"Bytecode enhancement" is divided into two types: Compilation and runtime. The compilation phase is to modify the class bytecode file compiled by the Java class and add the "enhancement" operation on it. (Do not understand why ?)

Lazy (optional-proxy by default): by default, single-point Association is performed by proxy. Lazy = "no-proxy" specifies that this attribute should be delayed when the instance variable is accessed for the first time (fetche lazily) (requires enhanced runtime bytecode ). Lazy = "false" indicates that the Association is always pre-captured. Note that if constrained = "false" and proxy cannot be used, Hibernate will pre-capture it!

Original post address: http://apps.hi.baidu.com/share/detail/38568475

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.