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

Description

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.

Attachments

3

Activity

Show:

Former user January 18, 2018 at 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 at 5:43 PM

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

Grigory Kislin November 26, 2017 at 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 at 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 at 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

Details

Assignee

Reporter

Components

Priority

Created January 16, 2009 at 4:40 PM
Updated January 18, 2018 at 9:21 PM
Resolved January 18, 2018 at 9:21 PM