[hibernate-dev] RE: EntityPersister.initializeLazyProperty: ask for one, initialize all?

Nikita Tovstoles nikita at doppelganger.com
Sun May 24 22:51:29 EDT 2009


Submitted a patch to Hibernate Core 3.3.1.GA that fixes the issue for multiple lazy one-to-one's on a shared PK. I think the only thing(s) left to do to enable un-batched lazy property initialization for cases other than one-to-one on a shared PK are:
- generate appropriate sql lazySelectString given property being requested (in AbstractEntityPersister.initializeLazyPropertiesFromDatastore)
- possibly alter CacheEntry to enumerate uninitialized properties (rather than simply store a boolean value)

I've tested my changes but, of course, would appreciate feedback from someone who knows Hibernate internals better than I do. My patch and further comments can be found here:
http://opensource.atlassian.com/projects/hibernate/browse/HHH-2309?focusedCommentId=33239#action_33239

-nikita


-----Original Message-----
From: hibernate-dev-bounces at lists.jboss.org [mailto:hibernate-dev-bounces at lists.jboss.org] On Behalf Of Nikita Tovstoles
Sent: Friday, May 22, 2009 8:57 PM
To: hibernate-dev at lists.jboss.org
Subject: [hibernate-dev] RE: EntityPersister.initializeLazyProperty: ask for one, initialize all?

Naturally, things are a bit more involved:
-replaced AbstractFieldInterceptor.initializing with a Set tracking that state on a per-fieldName basis.

That wasn't enough - TestLazyExecutable is failing - returning a null value - it almost seems as though the same FilterInterceptor instance is reused by multiple sessions after my awesome coding.

I assumed that at most (or exactly?) one AbstractFieldInterceptor impl instance is created per entity instance per Session and that no fieldInterceptor is used by multiple sessions. 

The interceptor seems to be injected with lazyProps only in PojoEntityTuplizer.afterInitialize() where the following comment resides:

//TODO: if we support multiple fetch groups, we would need
//      to clone the set of lazy properties!
FieldInterceptionHelper.injectFieldInterceptor( entity, getEntityName(), lazyProps, session );


Why is cloning needed? Is it because my assumption about the lifespan of one is incorrect? Is a new FieldInterceptor created every time a different lazy property is accessed for the first time on the same entity?

Thanks

-nikita




-----Original Message-----

Our app fails to scale sufficiently and I'd traced our problems to eager loading of all OneToOne relations when any single one is accessed. I would like to fix that but wanted to get feedback first. I'm referring to Hibernate Core 3.3.1.GA below:

Currently in AbstractFieldInterceptor.intercept():
"uninitializedFields = null; //let's assume that there is only one lazy fetch group, for now!"

proposed fix: 
-after 'result' is returned call uninitializedFields.remove(fieldname). Question: should this only be done if result != null?

And then AbstractEntityPersister.initializeLazyProperties() calls methods that initialize *all* properties even though a specific fieldname is supplied:
* initializeLazyPropertiesFromDatastore or
* initializeLazyPropertiesFromCache

Proposed fix:
-In both cases, determine appropriate 'j' value by searching lazyPropertyNames for 'fieldName'
-only call nullSafeGet, and initializeLazyProperty( fieldName, entity, session, snapshot, j, propValue ) once.


What do folks think?

Thanks,
-nikita


_______________________________________________
hibernate-dev mailing list
hibernate-dev at lists.jboss.org
https://lists.jboss.org/mailman/listinfo/hibernate-dev

_______________________________________________
hibernate-dev mailing list
hibernate-dev at lists.jboss.org
https://lists.jboss.org/mailman/listinfo/hibernate-dev




More information about the hibernate-dev mailing list