bug #6546
Updated by Andreas Müller about 7 years ago
Probably this is related to the size() problem in PersistentLists (see #5211): If a PersistentList is detached (not bound to a session) it adds new objects NOT to the underlying list but to an operationQueue. The operation queue is handled during reattache.
~~~ java
(from PersistentList line 312ff)
@Override
@SuppressWarnings("unchecked")
public void add(int index, Object value) {
if ( index < 0 ) {
throw new ArrayIndexOutOfBoundsException( "negative index" );
}
if ( !isInitialized() || isConnectedToSession() ) {
// NOTE : we don't care about the inverse part here because
// even if the collection is inverse, this side is driving the
// writing of the indexes. And because this is a positioned-add
// we need to load the underlying elements to know how that
// affects overall re-ordering
write();
list.add( index, value );
}
else {
queueOperation( new Add( index, value ) );
}
}
~~~
The objects in the operationQueue are NOT considered when calling PersistentList.size().
Therefore calls to size like in IdentifiableEntity.addIdentifier() create unexpected results.
~~~ java
@Override
public void addIdentifier(Identifier identifier){
addIdentifier(getIdentifiers().size(), identifier);
}
~~~
The problem only exists if add() is called with an index, like add(int, obj). The default add(obj) handles the list as expected:
~~~ java
@Override
public boolean add(Object object) {
if ( !isOperationQueueEnabled() ) {
write();
return list.add( object );
}
else {
queueOperation( new SimpleAdd( object ) );
return true;
}
}
~~~