Во время написания своего приложения я столкнулся с проблемой при выполнении оператора SQL.Я пытался найти решение в сети, но ни один из найденных не помог, и я до сих пор не знаю, как справиться с ошибкой, которую я получаю.Вот исключение, которое я получаю:
org.springframework.dao.DataIntegrityViolationException: could not execute statement; SQL [n/a]; constraint ["FKAM8LLDERP40MVBBWCEQPU6L2S: PUBLIC.BOOK_CATEGORY FOREIGN KEY(CATEGORY_ID) REFERENCES PUBLIC.CATEGORY(ID) (2)"; SQL statement:
insert into book_category (book_id, category_id) values (?, ?) [23506-196]]; nested exception is org.hibernate.exception.ConstraintViolationException: could not execute statement
А вот так классы выглядят: Book.class
@Entity
@Table(name = "book")
public class Book {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column(nullable = false)
private String title;
private String description;
@Column(name = "release_date")
@Temporal(TemporalType.TIMESTAMP)
private Date releaseDate;
@JoinColumn(name = "cover_image")
@OneToOne(cascade = CascadeType.MERGE)
private UploadFile coverImage;
@OneToOne(cascade = CascadeType.MERGE)
private UploadFile content;
@ManyToMany
@JoinTable(name = "book_category", joinColumns = {@JoinColumn(name = "book_id", referencedColumnName = "id")},
inverseJoinColumns = {@JoinColumn(name = "category_id", referencedColumnName = "id")})
private Set<Category> categories;
// constructors, setters, getters
}
Category.class
@Entity
@Table(name = "category")
public class Category {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column(name = "category_name")
private String name;
@ManyToMany(mappedBy = "categories", fetch = FetchType.LAZY)
private List<Book> books;
// ...
}