title: JPA and Hibernate Cascade DELETE OneToMany does not work
body: <p>I've been reading post after post and article after article trying to get cascade deletes to work with JPA/Hibernate in the latest Spring Boot version. I've read that You have to use Hibernate specific cascades and I've read that you don't. I've read that they just don't work but it seems to be a mixed bag. Everything I've tried doesn't work. The relationship is bi-directional.</p>
  
  <p>Doesn't Work:</p>
  
  <pre><code>@Entity
  public class Brand {
  
      @OneToMany(mappedBy = "brand", orphanRemoval = true, fetch = FetchType.LAZY)
      @Cascade({CascadeType.DELETE})
      @JsonManagedReference("brand-tax-rate")
      private List&lt;TaxRate&gt; taxRates;
  
  }
  </code></pre>
  
  <p>Doesn't Work:</p>
  
  <pre><code>@Entity
  public class Brand {
  
      @OneToMany(mappedBy = "brand", cascade = CascadeType.REMOVE, orphanRemoval = true, fetch = FetchType.LAZY)
      @JsonManagedReference("brand-tax-rate")
      private List&lt;TaxRate&gt; taxRates;
  
  }
  </code></pre>
  
  <p>Does anything work other than deleting the <code>TaxRates</code> prior to deleting the <code>Brand</code> ?</p>
  
  <p>My test looks like this:</p>
  
  <pre><code>@RunWith(SpringJUnit4ClassRunner.class)
  @SpringBootTest(classes = {Application.class, SpringSecurityConfig.class})
  @ActiveProfiles("test")
  @Transactional
  public class CascadeTests {
  
      @Autowired
      private BrandService brandService;
  
      @Autowired
      private TaxRateLoaderService taxRateLoaderService;
  
      @Autowired
      private TaxRateService taxRateService;
  
      @Autowired
      private TaxRateRepository taxRateRepository;
  
      @Autowired
      private BrandRepository brandRepository;
  
      @Test
      public void testCascadeWorks() throws Exception {
  
          taxRateLoaderService.loadData(null, 10);
  
          // if I uncomment this then I'm good
          // but shouldn't have to if cascade works
          //taxRateService.deleteAll();
          brandService.deleteAll();
  
          List&lt;TaxRate&gt; rates = Lists.newArrayList(taxRateRepository.findAll());
          List&lt;Brand&gt; brands = Lists.newArrayList(brandRepository.findAll());
  
          Assert.assertEquals(rates.size(), 0);
          Assert.assertEquals(brands.size(), 0);
      }
  }
  </code></pre>
  
  <p>Error for reference:</p>
  
  <blockquote>
    <p>Caused by: org.h2.jdbc.JdbcSQLException: Referential integrity
    constraint violation: "FKC4BCIKI2WSPO6WVGPO3XLA2Y9: PUBLIC.TAX_RATE
    FOREIGN KEY(BRAND_ID) REFERENCES PUBLIC.BRAND(ID) (1)"; SQL statement:
    delete from brand where id=? [23503-192]</p>
  </blockquote>
  
  <p>UPDATE: modified my <code>brandService.deleteAll()</code> method to do the following:</p>
  
  <pre><code>@Override
  public void deleteAll() {
      Iterable&lt;Brand&gt; iter = this.brandRepository.findAll();
      iter.forEach(brand -&gt; this.brandRepository.delete(brand) );
  }
  </code></pre>
  
  <p>Still does not work.</p>
  
  <p>UPDATE 2: It only appears to be a problem via tests. Cascade seems to work okay with the app running.</p>