'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. Missing index for constraint '' in the referenced table ''
caused by Failed to add the foreign key constraint. Missing index for constraint '' in the referenced table ''
Below are my entity 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<>();
Below is another entity class for manytoOneampping
@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;
Solution 1:[1]
I noticed in db, duplicates tables were being created so that's why i was getting that error
Adding below annotation solved my problem :
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | med benzekri |