Batch loading the same EntityKey (one side of manytoone ) more than once

Description

Within the same session, the same entity gets batch loaded multiple times. The ManyToOneType.scheduleBatchLoad calls BatchFetchQueue.addBatchLoadableEntityKey without checking to see if the entity already exists with the current PersistanceContext. Adding the extra condition "!context.containsEntity(key)" to the BatchFetchQueue.addBatchLoadableEntityKey method which seems to address the issue.

public void addBatchLoadableEntityKey(EntityKey key) {
if ( key.isBatchLoadable() && !context.containsEntity(key) ) {
batchLoadableEntityKeys.put(key, MARKER);
}
}

This will save few loops if we have large set of Entity being lodaded with each of them having manytoone relationship with other Entity.

Activity

Steve EbersoleJune 15, 2006 at 6:42 PM

Not quite the correct solution. TheRightThing is to modify ManyToOneType to have it make sure it should be adding something to the batcj fetch queue before it actually does. Adding that check in BatchFetchQueue.addBatchLoadableEntityKey() acutally causes unnecessary overhead to the other current caller of that method: DefaultLoadEventListener, where we already know for a fact that the entity is not associated with the session.

Added the necessary changes to ManyToOneType

Fixed

Details

Assignee

Reporter

Components

Fix versions

Priority

Created June 12, 2006 at 7:32 AM
Updated June 15, 2006 at 6:42 PM
Resolved June 15, 2006 at 6:42 PM