I saw in unidirectional @ManytoOne, the removal does not work as expected. When the parent is deleted, ideally the child should also be deleted, but only the parent will be deleted, and the child will NOT be deleted and remain an orphan
The following technologies are used: Spring Boot / Spring Data JPA / Hibernate
Sprint Boot: 2.1.2.RELEASE
Spring Data JPA / Hibernate used to remove .eg string
parentRepository.delete(parent)
ParentRepository extends the standard CRUD repository, as shown below ParentRepository extends CrudRepository<T, ID>
Below is my entity class
@Entity(name = 'child') public class Child { @Id @GeneratedValue private long id; @ManyToOne( fetch = FetchType.LAZY, optional = false) @JoinColumn(name = 'parent_id", nullable = false) @OnDelete(action = OnDeleteAction.CASCADE) private Parent parent; } @Entity(name = 'parent') public class Parent { @Id @GeneratedValue private long id; @Column(nullable = false, length = 50) private String firstName; }
ranjesh Feb 11 '19 at 15:57 2019-02-11 15:57
source share