com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException:无法添加或更新子行:外键约束失败(
ravermeister
。artist_recordlabel
,CONSTRAINTFK_9dgdyft45droyopxsqijwb1dx
FOREIGN KEY(artist_id
)参考artist
(id
))
艺术家课
@Entity
@Repository
@Data
@NoArgsConstructor(force = true)
public class Artist {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private long id;
@Column(name = "artist_firstname")
private String artist_firstname;
@Column(name = "artist_secondname")
private String artist_secondname;
@Column(name = "artist_nickname")
private String artist_nickname;
@ManyToMany (fetch = FetchType.LAZY, cascade = {CascadeType.PERSIST, CascadeType.MERGE})
@JoinTable(name = "artist_recordlabel", joinColumns = @JoinColumn(name = "artist_id"),
inverseJoinColumns = @JoinColumn(name = "label_id"))
private Set<RecordLabel> recordLabels;
@ManyToMany (fetch = FetchType.LAZY, cascade = {CascadeType.PERSIST, CascadeType.MERGE})
@JoinTable (name = "artist_musicrelease", joinColumns = @JoinColumn (name = "artist_id"),
inverseJoinColumns = @JoinColumn (name = "musicrelease_id"))
private Set <MusicRelease> musicReleaseSet;
和RecordLabel类
@Entity
@Repository
@Data
@NoArgsConstructor(force = true)
public class RecordLabel {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private long id;
@Column(name = "label_name")
private String label_name;
@Column(name = "label_country")
private String label_country;
@ManyToMany(fetch = FetchType.LAZY, cascade = {CascadeType.PERSIST, CascadeType.MERGE})
@JoinTable(name = "artist_recordlabel", joinColumns = @JoinColumn(name = "label_id"),
inverseJoinColumns = @JoinColumn(name = "artist_id"))
private Set<Artist> artistsList;