Skip to content
Snippets Groups Projects

Update Hibernate DAO to not error out when there are no results to

1 file
+ 3
5
Compare changes
  • Side-by-side
  • Inline
@@ -11,7 +11,6 @@ import java.util.List;
import javax.inject.Inject;
import javax.persistence.EntityManager;
import javax.persistence.NoResultException;
import javax.persistence.TypedQuery;
import javax.transaction.Transactional;
@@ -121,11 +120,10 @@ public class DefaultHibernateDao implements PersistenceDao {
}
// retrieve results for the given deletion query to delete using entity manager
List<T> results = get(q);
if (results.isEmpty()) {
throw new NoResultException("Could not find any documents with given filters");
if (results != null) {
// remove all matched documents
results.forEach(em::remove);
}
// remove all matched documents
results.forEach(em::remove);
}
@Transactional
Loading