通过 JDBC 语句执行 DDL "alter table add constraint foreign key () references (id)" 时出错
Error executing DDL "alter table add constraint foreign key () references (id)" via JDBC Statement
Error executing DDL "alter table child add constraint foreign key (parent_id) references (id)" via JDBC Statement caused by Failed to add the foreign key constraint.引用的 table ''
中缺少约束 '' 的索引
造成的
添加外键约束失败。引用的 table ''
中缺少约束 '' 的索引
下面是我的实体class
@Entity
@Table(name = "parent")
public class Parent {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@OneToMany(mappedBy = "parent", cascade = { CascadeType.PERSIST,
CascadeType.MERGE }, fetch = FetchType.EAGER, orphanRemoval = true)
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
private Set<Child> child = new HashSet<>();
下面是 manytoOneampping
的另一个实体 class
@Entity
@Table(name = "child")
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class Child implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@ManyToOne
@JoinColumn(name = "parent_id")
@JsonIgnoreProperties("child")
private Parent parent;
我注意到在数据库中,正在创建重复的表,这就是我收到该错误的原因
添加以下注释解决了我的问题:
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
Error executing DDL "alter table child add constraint foreign key (parent_id) references (id)" via JDBC Statement caused by Failed to add the foreign key constraint.引用的 table ''
中缺少约束 '' 的索引造成的 添加外键约束失败。引用的 table ''
中缺少约束 '' 的索引下面是我的实体class
@Entity
@Table(name = "parent")
public class Parent {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@OneToMany(mappedBy = "parent", cascade = { CascadeType.PERSIST,
CascadeType.MERGE }, fetch = FetchType.EAGER, orphanRemoval = true)
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
private Set<Child> child = new HashSet<>();
下面是 manytoOneampping
的另一个实体 class@Entity
@Table(name = "child")
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class Child implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@ManyToOne
@JoinColumn(name = "parent_id")
@JsonIgnoreProperties("child")
private Parent parent;
我注意到在数据库中,正在创建重复的表,这就是我收到该错误的原因
添加以下注释解决了我的问题:
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)