Calling getter for id when using AccessType( "field" ) causes proxy initialization.
In org.hibernate.proxy.proxy.pojo.BasicLazyInitializer there is the code
However, when using field access, the getIdentifierMethod will be null. I fixed this for us by changing DirectPropertyAccessor by adding a Method attribute to the DirectGetter inner class, and looking up the appropriate getter in the constructor. As far as I can tell, getMethod is only used in two places. In the above case, to the get the identity getter and in PojoComponentTupilizer.isMethodOf. This doesn't seem to break anything. I don't know if this is a clean solution, seems a little hacky to me, however, it would be great if the issue could be fixed somehow.
hibernate 3.3.1, hibernate annotations 3.4.0, running on windows, linux and solaris, using sybase 15
Thanks for the reply, Steve. Is there already an issue open that you're aware of for the fact that we're initializing an entity when attempting to access transient state?
My situation is that I have entity inheritance with Discriminators. If a field's declared type is one of the subtypes (not the abstract supertype), then I should be able to determine what it's discriminator is by way of knowing its declared type. A proxy for that property shouldn't have to initialize and load the discriminator out of the database, a method on the entity should be able to return a static value without causing initialization.
Added a test case that asserts the expected behavior. Note that the project has two profiles, no-enhancement and do-enhancement. Both should work but fail.
In 5.2.11.Final version bug still exist, but in 5.2.12.Final second request for proxy initialization disappeared.
Please check: fixed at last?
Version 5.2.12.Final - fixed.
@Strong Liu - please confirm.
I think this is fixed in 5.2.12 by HHH-11838.
Please not that this may end up getting broken when HHH-12034 is fixed. When that happens, you will probably need to opt-in to this functionality by setting a configuration parameter.