|
I disagree that this is documented behavior. I could not find anywhere in the Hibernate Core Reference Manual that explains this.
The closest thing I found was this:
20.1.3. Single-ended association proxies ... By choosing lazy="no-proxy" instead of the default lazy="proxy", you can avoid problems associated with typecasting. However, buildtime bytecode instrumentation is required, and all operations will result in immediate proxy initialization.
But this is talking about using lazy="no-proxy", not field access.
On the contrary, the documentation twice promises that calling the identifier getter on an uninitialized proxy does not require proxy initialization:
20.1. Fetching strategies ... Proxy fetching: a single-valued association is fetched when a method other than the identifier getter is invoked upon the associated object.
and
20.1.3. Single-ended association proxies ... Certain operations do not require proxy initialization:
-
equals(): if the persistent class does not override equals()
-
hashCode(): if the persistent class does not override hashCode()
-
The identifier getter method
In neither case are these statements qualified with "except when using field access."
And the discussion about choosing which access type to use (5.1.4.1.2. Access type) does not mention any differences in proxy behavior. The documentation does recommend property access, but it does not give any specific reasons to choose it over field access.
|