[hibernate-dev] Too simple a solution for HHH-11147 ?
Thomas Reinhardt
thomas at reinhardt.com
Wed Sep 27 17:33:15 EDT 2017
Hello,
I investigated HHH-11147 (Allow enhanced entities to be returned in a
completely uninitialized state) and have a very small fix for that issue.
I want your feedback if I am going the correct route here. Seems too
easy and lazy loading is a pretty important piece of hibernate.
To spare everyone opening the issue just to get an overview here is a
short summary:
The use case is an entity with a simple relation:
@Entity
@Proxy(lazy=true)
class MyEntity {
@ManyToOne(fetch=FetchType.LAZY)
OtherEntity other;
}
Both entities are bytecode enhanced at compiletime with
enableLazyInitialization=true. The problem is that the "other" entity is
fetched despite being annotated as lazy.
My quick fix is actually only two changed lines. A proper diff
(HHH-11147-quick-and-dirty.diff) is attached to the issue. I did
specifically not make a PR just for this discussion but if requested I
can of course make one. A pseudo-diff can be found below.
I did test this fix on our main application and it seems to work. There
are two main questions:
1) could there be cases where we create a proxyFactory without need?
2) am I killing the benefits of the bytecode enhancement by using a
proxy or do I still get things like association handling?
Sorry for the wall of text but I thought this discussion does not belong
in the issue itself. Correct me if I am wrong.
Greetings,
Thomas
Pseudo-diff:
org.hibernate.event.internal.DefaultLoadEventListener
proxyOrLoad(LoadEvent, EntityPersister, EntityKey, LoadType) {
...
// this class has no proxies (so do a shortcut)
- if ( !persister.hasProxy() ) {
+ if ( !persister.getEntityMetamodel().isLazy() ) {
return load( event, persister, keyToLoad, options );
...
}
org.hibernate.tuple.entity.AbstractEntityTuplizer
public AbstractEntityTuplizer(...) {
...
instantiator = buildInstantiator( entityMetamodel, mappingInfo );
- if ( entityMetamodel.isLazy() &&
- !entityMetamodel.getBytecodeEnhancementMetadata()
- .isEnhancedForLazyLoading() ) {
+ if ( entityMetamodel.isLazy() ) {
proxyFactory = buildProxyFactory( ... );
...
}
More information about the hibernate-dev
mailing list