spring boot: Cannot delete or update a parent row: a foreign key constraint fails

Viewed 2044

I have the following class:

@EmbeddedId
private BookAuthorId id;

@ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
@MapsId("bookIsbn")
private Book book;

@ManyToOne(fetch = FetchType.LAZY)
@MapsId("authorId")
private Author author;

@NotNull(message = "Author's index can not be null")
@Column(name = "author_index")
private Integer index;

}

So, basically, I try to delete a book without any author and it works, when I have some authors with a book I get: java.sql.SQLIntegrityConstraintViolationException: Cannot delete or update a parent row: a foreign key constraint fails (books.books_authors, CONSTRAINT FKg92282id84r9l5youm7y12vpg FOREIGN KEY (book_isbn) REFERENCES books (isbn))

Some ideas?

Ty

1 Answers
Related