final methods on entity silently breaks lazy proxy loading

Description

When property getter is defined as final on entity B and that entity is lazy loaded from association from entity A, calling that final getter does not trigger lazy loading. Call just silently fails and returns null.

There should be no need to define getter as final, but some exception would be nice here to detect these kind of bugs on entities.

Activity

Show:

Former user February 10, 2018 at 1:48 AM

Rejected since it's not a bug and working as expected.

Ilpo Kettunen November 30, 2017 at 7:24 AM

I do not know how, but I had to say I missed that log line completely while testing. Yes, it's there.

In my opinion you could consider throwing exception here since returned proxy is mostly unusable anyway.

Maybe there could be some general setting, with sensible defaults, which HHHxxxxxx loggers throws exception?

Luis Barreiro November 28, 2017 at 3:46 PM

you mean something like this:

ERROR PojoEntityTuplizer:142 - HHH000112: Getters of lazy classes cannot be final: org.hibernate.test.lazyload.LazyLoadingEntityWithFinalGetterTest$B.text

I see that on the logs generated by your test.
See https://github.com/hibernate/hibernate-orm/blob/master/hibernate-core/src/main/java/org/hibernate/tuple/entity/PojoEntityTuplizer.java#L142

Note that the proxy is still created ... it's just that those final methods bypass the proxy.

Ilpo Kettunen November 28, 2017 at 1:45 PM

I just wonder if we can get some kind of warning that proxy can not be created?

Luis Barreiro November 28, 2017 at 1:33 PM

Hibernate does proxy by subclassing. Methods declared final can't be overriden, and therefore they can't be added to the proxy. When a final method is invoked it's invoked on the target object, bypassing the proxy.
The proxies are generated by 3rd party libraries, so that process it's not under hibernate.

Rejected

Details

Assignee

Reporter

Components

Priority

Created November 23, 2017 at 10:39 AM
Updated February 10, 2018 at 1:49 AM
Resolved February 10, 2018 at 1:48 AM