call to id getter initializes proxy when using AccessType( "field" )


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


Gail Badner
January 18, 2018, 9:20 PM

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.

Grigory Kislin
January 17, 2018, 5:43 PM

Version 5.2.12.Final - fixed.
@Strong Liu - please confirm.

Grigory Kislin
November 26, 2017, 3:00 AM

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?

Christian Beikov
October 3, 2016, 9:54 AM

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.

Tim Whitbeck
April 11, 2014, 6:15 PM

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.

Out of Date


Strong Liu


Paul Lorenz