I want to delete any attached child objects when removing a parent from DB. But it does not work:
@Entity
public class ParentEntity {
@Id
private Long id;
//must remain unidirectional
@OneToOne(cascade = CascadeType.ALL, orphanRemoval = true)
private MyEntity my;
}
@Entity
public class MyEntity {
private String text;
}
public interface ParentEntityRepository extends CrudRepository<ParentEntity, Long> {}
When I execute:
@Autowired
private ParentEntityRepository dao;
@Transactional
public void removeId(long id) {
dao.delete(id);
}
Result:
MyEntity
row still exists in DB! Why?