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