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

CrudRepository.deleteAll doesn't work

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Investigating
    • Priority: Major
    • Resolution: Unresolved
    • Affects Version/s: 2.2.3 (Moore SR3)
    • Fix Version/s: None
    • Component/s: Core

      Description

      CrudRepository.deleteAll() doesn't work on Entity repository if the proxies loaded by findAll are not initialized. Simplified example:

      entities:

      @MappedSuperclass
      class Base {
        @EmbeddedId
        protected EntityId id;
      
        @Version
        private Timestamp timestamp;
      }
      
      @Entity
      class A extends Base {
      
        @ManyToOne(optional = false, fetch = FetchType.LAZY)
        private B b;
      }
      
      @Entity
      class B extends Base {
      }

       

      client:

      // create A and related B entities in a separate transaction
      
      // start transaction
      aRepository.deleteAll();
      bRepository.deleteAll();
      //end transaction

       

      B entities are not deleted in this case because: SimpleJpaRepository.delete(T entity):

      if (entityInformation.isNew(entity)) {
       return;
      }
      

       

      entityInformation.isNew returns true for B entities.

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              schauder Jens Schauder
              Reporter:
              Winiarski Michał Winiarski
              Last updater:
              Jens Schauder
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Dates

                Created:
                Updated: