当我尝试在我的应用程序中创建一个新类别时,我收到以下错误,它抱怨 FK 约束。但是,它抱怨的 FK 将类别描述映射到类别,因为两者都是同时创建的,我不确定为什么会出现问题。
我可以毫无问题地更新类别和类别描述。
错误
ERROR - Cannot add or update a child row: a foreign key constraint fails (`crcart3`.`categorydescription`, CONSTRAINT `FKC6C4CBFE6FD28044` FOREIGN KEY (`category_description_id`) REFERENCES `categorydescription` (`category_id`))
类别表
@Table(name = "Category")
public class Category {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "category_id")
private int categoryId;
@JoinTable(
name = "ImageMapping",
joinColumns = @JoinColumn(name = "category_id"),
inverseJoinColumns = @JoinColumn(name = "image_id")
)
@OneToOne(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
private Image categoryImageId;
@JoinTable(
name="CategoryDescription",
joinColumns = @JoinColumn(name="category_id"),
inverseJoinColumns = @JoinColumn(name="category_description_id")
)
@OneToOne(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
private CategoryDescription categoryDescription;
@JoinTable(
name = "CategoryMapping",
joinColumns = @JoinColumn(name = "category_id"),
inverseJoinColumns = @JoinColumn(name = "parent_category_id")
)
@ManyToOne(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
private Category parentCategory;
@Column(name = "category_sort_order")
private int sortOrder;
@Column(name = "date_added")
private Timestamp dateAdded;
@Column(name = "last_modified")
private Timestamp lastModified;
类别描述表
@Table(name="CategoryDescription")
public class CategoryDescription {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "category_description_id")
private int categoryDescriptionId;
@Column(name="category_id")
private int categoryId;
@OneToOne
@JoinColumn(name="language_id")
private Language languageId;
@Column(name="category_name")
private String categoryName;
@Column(name="category_text")
private String categoryText;