I load an Object that contains a lazy inverse List (one-to-many).
My collection is wrapped by a PersistentMap
There is objects in the collection in the database but in my case the PersistentMap is not yet initialized.
I perform a remove operation on the persistentMap with a known key of one of the objects.
The map is not initialized (and the relation is an inverse one-to-many) so the map queue the removeOperation.
I perform a get operation with the same key and the value is still returned.
If we look closer at what happened in the PersistentMap, it's look like this.
Code:
public Object remove(Object key) {
if ( isPutQueueEnabled() ) { // This returned true, the
// map is not yet
// initialized
Object old = readElementByIndex( key ); // This method triggered
// an initialization of the
// map.
// Queued operation are
// processed in the after
// init method
queueOperation( new Remove( key, old ) ); // The remove operation
// is queued.
return old;
}
....
When i perform the get operation on the map the map is now initialized. The get is processed by the underlying map and the value is returned. The queued operation is completely ignored.
Im i doing something wrong?
Currently i fixed my code by performing a containsKey before the remove . The containsKey initialize the map and then the remove do not queue the operation. But by looking at all the PersistentCollection it seem that i may have the same problem using put and remove with other persistentCollection.