[ad_1]
I tried to delete a record in ratings table,then Cannot add or update a child row: a foreign key constraint fails (fyprojectdb
.ratings
, CONSTRAINT FKdyash6f91887unaan9mj9b460
FOREIGN KEY (answer_id
) REFERENCES answers
(answer_id
)) this error occured. How to ix this error. I have mapped both entities correctly.
@Entity
@Table(name = "ratings")
public class Ratings {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long rating_id;
@Column(nullable = false, unique = false, length = 45)
private Short ratingValue;
@ManyToOne(cascade = CascadeType.ALL)
@JoinColumn(name = "userId")
private User user;
@ManyToOne(cascade = CascadeType.ALL)
@JoinColumn(name = "answer_id")
private Answer answer;
@ManyToOne(cascade = CascadeType.ALL)
@JoinColumn(name = "question_id")
private Question question;
//getters and setters
@Entity
@Table(name = "answers")
public class Answer {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long answer_id;
@Column(nullable = false, unique = false, length = 100)
private String fullAnswer;
/*Many to one mapping question*/
@ManyToOne(cascade = CascadeType.REMOVE)
@JoinColumn(name = "question_id")
private Question question;
/* Many to One mapping with users*/
@ManyToOne(cascade = CascadeType.REMOVE)
@JoinColumn(name = "userId")
private User user;
//getters and setters
[ad_2]