Uploaded image for project: 'Spring Data JPA'
  1. Spring Data JPA
  2. DATAJPA-907

Add JpaSpecificationExecutor.delete(…) and ….deleteAll(…)

    Details

    • Type: New Feature
    • Status: Open
    • Priority: Major
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: Core
    • Labels:

      Description

      I have to delete massive entities. And I cannot add deleteByXxxxx(...) to repository by some reason. So, I implemented deleteAll(Specification) myself for general-purpose. I think it would be nice that JpaSpecificationExecutor has deleteAll(Specification) interface.

      Please consider this.

      Example for SimpleJpaRepository (Worked with transaction)

      private EntityManager entityManager;
      private Class<E> entityClass;
      
      public int deleteAll(Specification<E> spec) {
      	
      	CriteriaBuilder builder = entityManager.getCriteriaBuilder();
      	CriteriaDelete<E> query = builder.createCriteriaDelete(entityClass);
      	
      	Predicate predicate = spec.toPredicate(query.from(entityClass), null, builder);
      	query.where(predicate);
      	
      	return entityManager.createQuery(query).executeUpdate();
      }
      

        Attachments

          Activity

            People

            • Assignee:
              olivergierke Oliver Drotbohm
              Reporter:
              hk SPT Developer
              Last updater:
              SPT Developer
            • Votes:
              2 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated: