I have a general question about the following methods:


Method-1: manager1.storeAll(Object...instances)

Method-2: manager2.storeAll(Iterable<?> instances)


Am I right with the following assumption:


Use Method-1 if you want to update all instances within a collection. It does NOT add or remove instances from the collection.

Use Method-2 if you want to add or remove instances from the collection. It does NOT update any existing instance within the collection.


So for example:


// updates the user instance and add/remove any tasks from user.getTasks() (existing task-instances will NOT be updated)
manager1.storeAll(user, user.getTasks());

// updates each task-instance within user.getTasks() (does NOT remove or add any task in user.getTasks())
manager2.storeAll(user.getTasks());


Are my assumptions of those two storeAll()-methods correct?

Be carefull, both methods behave the same way, the difference is only the parameter type. Both will store(update) the passed objects inside the Iterable<?> or array that is used as parameter to pass those elements to the storeAll methods, the Iterable<?> or array itself will not be stored.


Internally both methods will result in a for loop:

for (Object object : instances){
   store(object)
}


So, your examples are correct, but the use case for Method-2 is wrong, it is the same as for Method-1.

Are you really sure that both methods are interchangable? I made the observation, that I need to call manager1.storeAll(Object...instances) to update a property of an existing object-instance living inside a stored collection? Using the manager2.storeAll(Iterable<?> instances) will not update this property - it will only add or remove whole object-instances from the collection.

Yes, both methods internally store every passed object instance but not the “container”.

Your observation that storeAll(Iterable<?> instances) adds/removes element from a collection is a bit unexpected.

Can supply the code that created that effect?

Thanks. I will try to find the issue that's causing this behaviour and give feedback to you after I know the cause.