Why saveOrUpdateAll is deprecated in spring HibernateOperations

Take a look at the source code .

There may be good reasons, but it’s strange that I could do hibernate.deleteAll and hibernate.loadAll , but not hibernate.saveOrUpdateAll (of course, I can do this in practice, but if this method is deprecated, it may disappear in the next version)

+6
source share
1 answer

The reason is obvious from Java docs,

in favor of using a separate saveOrUpdate or merge

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

 public void saveOrUpdateAll(final Collection entities) throws DataAccessException { 768 executeWithNativeSession(new HibernateCallback() { 769 public Object doInHibernate(Session session) throws HibernateException { 770 checkWriteOperationAllowed(session); 771 for (Iterator it = entities.iterator(); it.hasNext();) { 772 session.saveOrUpdate(it.next()); 773 } 774 return null; 775 } 776 }); 777 } 

This method has been less used; it cannot be inside your transaction. So spring wants you to iterate over the list and save individual objects.

The loadAll() method is different and useful. It does not look like saveOrUpdateAll() .

You are right with your observation that deleteAll() is similar to saveOrUpdateAll() , and I agree that it is incompatible, but it is deprecated and the other is not.

+10
source

Source: https://habr.com/ru/post/913110/


All Articles