Java – how to prevent hibernate from eagerly obtaining many to one associated objects
I have an attribute in a domain object that is declared in a many - to - one element The basic syntax of this attribute is as follows:
<many-to-one name="propertyName" class="propertyClass" fetch="select" not-found="ignore" lazy="proxy" />
Now, the idea is to make hibernate not rush to get this property It may be null, so the unset ignore is set
However, when hibernate loads the class containing this association, it will load itself into the actual class (or even proxy) instance when loading the parent class Because the size of some attributes exceeds 1MB, it takes up a lot of heap space
However, if no exception is found (or the default is exception), the parent class with this property will load the agent!
How to stop hibernate without loading the proxy while still allowing this property to be empty?
I found that lazy = no proxy, but the document talks about some bytecode modification, which is not described in detail Can someone help me?
If it is important, it is the Java version of hibernate, and it is at least version 3 (I can find the actual version if it helps, but now it is hibernate 3)
I didn't specify it before, but the Java version is 1.4 Therefore, Java annotations are not supported
Solution
If the other end of the association can be empty, I believe hibernate must query the end of the association to determine whether it should use a proxy (no proxy is required if the other end is empty) I can't find this reference now, but I remember reading somewhere
In order to provide delayed loading fields, the document references the bytecode enhancement of the fields in buildtime: using lazy property fetching This is an excerpt: