Использую хибернейт для создания таблиц.
Из ошибки я понимаю таблица создаётся таким образом что не возможно удалить или апдейдить родителя ..
Как настроить хибернейт на создания таблици с возможностью апдейда или удаления родителя ?
Cannot delete or update a parent row: a foreign key constraint fails (`couponsystem`.`company_employees`, CONSTRAINT `FK8qf6rpgr5asjrokumh155o3jr` FOREIGN KEY (`COMPANY_ID`) REFERENCES `companies` (`COMPANY_ID`))
DELETE FROM companies WHERE COMPANY_ID = "8768765";
@Entity
@Table(name = "companies")
public class Company implements Serializable{
public Company() {}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Company company = (Company) o;
if (id != company.id) return false;
if (!compName.equals(company.compName)) return false;
if (!password.equals(company.password)) return false;
return email.equals(company.email);
}
@Override
public int hashCode() {
int result = (int) (id ^ (id >>> 32));
result = 31 * result + compName.hashCode();
result = 31 * result + password.hashCode();
result = 31 * result + email.hashCode();
return result;
}
public Collection<Customer> getCompany_customers() {
return company_customers;
}
public void setCompany_customers(Collection<Customer> company_customers) {
this.company_customers = company_customers;
}
public Collection<Coupon> getCompany_coupons() {
return company_coupons;
}
public void setCompany_coupons(Collection<Coupon> company_coupons) {
this.company_coupons = company_coupons;
}
@OneToMany
@JoinTable(name = "company_customers" , joinColumns = @JoinColumn(name = "COMPANY_ID") , inverseJoinColumns = @JoinColumn(name = "CUSTOMER_ID"))
private Collection<Customer> company_customers;
@OneToMany
@JoinTable(name = "company_coupons" , joinColumns = @JoinColumn(name = "COMPANY_ID") , inverseJoinColumns = {@JoinColumn(name = "COUPON_ID")})
private Collection<Coupon> company_coupons;
@OneToMany
@JoinTable(name = "company_employees" , joinColumns = @JoinColumn(name = "COMPANY_ID") , inverseJoinColumns = @JoinColumn(name = "EMPLOYEE_ID"))
private Collection<Employee> company_employee;
@Id
@Column(name = "COMPANY_ID")
@Size(min = 5 , max = 20 , message = "Company id must be 5 - 20")
private long id;
@Column(name = "COMPANY_NAME")
@NotBlank(message = "Company name can't be empty! ")
private String compName;
@Column(name = "COMPANY_PASSWORD")
@Pattern(regexp = "((?=.*\\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[@#$%]).{6,20})",
message = "Wrong password! Correct examples: " +
"1. mkyong1A@\n" +
"2. mkYOn12$")
private String password;
@Column(name = "COMPANY_EMAIL")
@Pattern(regexp = "^[_A-Za-z0-9-\\+]+(\\.[_A-Za-z0-9-]+)*@"
+ "[A-Za-z0-9-]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$",
message = "Wrong email! Correct examples: " +
"1. mkyong@yahoo.com, mkyong-100@yahoo.com, mkyong.100@yahoo.com\n" +
"2. mkyong111@mkyong.com, mkyong-100@mkyong.net, mkyong.100@mkyong.com.au\n" +
"3. mkyong@1.com, mkyong@gmail.com.com\n" +
"4. mkyong+100@gmail.com, mkyong-100@yahoo-test.com")
private String email;
@Override
public String toString() {
return "Company [id=" + id + ", compName=" + compName + ", password=" + password + ", email=" + email +"]";
}
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getCompName() {
return compName;
}
public void setCompName(String compName) {
this.compName = compName;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
}