Why saveOrUpdateAll is deprecated in spring HibernateOperations

hibernate, java, spring

Solution

The reason is clear from the Java docs,

in favor of individual saveOrUpdate or merge usage

As you can see the implementation of the method, code taken from the link,

public void saveOrUpdateAll(final Collection entities) throws DataAccessException {
    executeWithNativeSession(new HibernateCallback() {
        public Object doInHibernate(Session session) throws HibernateException {
            checkWriteOperationAllowed(session);
            for (Iterator it = entities.iterator(); it.hasNext(); ) {
                session.saveOrUpdate(it.next());
            }
            return null;
        }
    });
}

This method was less used, it can not be inside your transaction. So, spring want you to iterate the list and save the individual objects.

The `loadAll()` method is different and useful. It is not similar to `saveOrUpdateAll()`.

You are right with your observations that `deleteAll()` is similar to `saveOrUpdateAll()` and I agree that it is inconsistent one is deprecated and the other one is not.

Problem

Take a look into source code. There could be valid reasons behind that, but it's strange that I could do `hibernate.deleteAll` and `hibernate.loadAll`, but not `hibernate.saveOrUpdateAll` (sure I can do that practically, but if this method is deprecated means that it could disappear in next release)

Original source