Cascade delete on Hibernate/Spring Data
<p>I have the following entities: </p>

<pre><code>@Entity
public class Car { ... }

@Entity
public class Driver {
    @ManyToOne(cascade=CascadeType.ALL)
    @JoinColumn(name = "CAR_ID")
    private Car car;

    ...
}

@Entity
public class Penalty {
    @ManyToOne(cascade=CascadeType.ALL)
    @JoinColumn(name="D_ID")
    private Driver driver;

    ...
}
</code></pre>

<p>I would like all information from <code>Driver</code> and <code>Penalty</code> deleted when a <code>Car</code> is deleted as <code>carRepository.delete(car_id)</code>.</p>

<pre><code>WARN : org.hibernate.engine.jdbc.spi.SqlExceptionHelper - SQL Error: 1451, SQLState: 23000
ERROR: org.hibernate.engine.jdbc.spi.SqlExceptionHelper - Cannot delete or update a parent row: a foreign key constraint fails (`test`.`car_drivers`, CONSTRAINT `FK9ux9oqx6yr66cva4ro6l8m63r` FOREIGN KEY (`CAR_ID`) REFERENCES `cars` (`CAR_ID`))
ERROR: org.hibernate.internal.ExceptionMapperStandardImpl - HHH000346: Error during managed flush [org.hibernate.exception.ConstraintViolationException: could not execute statement]
ERROR: com.app.cars.controller.AdminController - Exception during deleting car due to  could not execute statement; SQL [n/a]; constraint [null]; nested exception is org.hibernate.exception.ConstraintViolationException: could not execute statement
</code></pre>

<p>Cannot make change in table attributes and design. So, need to get rid of this error by fixing the entity model.</p>