Home Hibernate delete from onetomany
Reply: 0

Hibernate delete from onetomany

user1474 Published in July 23, 2018, 1:40 pm

I have two tables with OneToMany relation

class ServiceProvider {


@OneToMany(fetch=FetchType.EAGER,mappedBy="serviceProvider", cascade={CascadeType.ALL,CascadeType.REMOVE},orphanRemoval = true) @OnDelete(action=OnDeleteAction.CASCADE) private List serviceCenters; ...


class ServiceCenterDetails {

... //bi-directional many-to-one association to ServiceProviderDomainMap @ManyToOne @JoinColumn(name="SERVICE_PROVIDER_ID") private ServiceProvider serviceProvider;



I am trying to delete provide row. But i am getting below error:

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))

below is the way i am trying

  String hql = "DELETE FROM ServiceProvider WHERE id =  :providerId";
  Query query = sessionFactory.getCurrentSession().createQuery(hql);

  int result = query.executeUpdate();

could someone pls help resolving it?

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.47387 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO