我有两个表格,它们之间存在OneToMany的关系。
class ServiceProvider {
...
@OneToMany(fetch=FetchType.EAGER,mappedBy="serviceProvider", cascade={CascadeType.ALL,CascadeType.REMOVE},orphanRemoval = true) @OnDelete(action=OnDeleteAction.CASCADE) private List serviceCenters; ...
}
class ServiceCenterDetails {
... //双向多对一与ServiceProviderDomainMap相关联 @ManyToOne @JoinColumn(name="SERVICE_PROVIDER_ID") private ServiceProvider serviceProvider;
...
}
我正在尝试删除提供者行。但是我遇到了以下错误:
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Cannot delete or update a parent row: a foreign key constraint fails (fixoline
.service_center_details
, CONSTRAINT FK_qvahoxeovx9vmwl6mcu2c0lyw
FOREIGN KEY (SERVICE_PROVIDER_ID
) REFERENCES service_provider
(ID
))
下面是我的尝试方式
String hql = "DELETE FROM ServiceProvider WHERE id = :providerId";
Query query = sessionFactory.getCurrentSession().createQuery(hql);
query.setParameter("providerId",providerId);
int result = query.executeUpdate();
请问有人能帮忙解决这个问题吗?