Reputation: 153
I am using spring MVC and hibernate framework .i have 2 tables .those are Team and Releases.it has a one to many mapping.i can delete recodes from Releases,but when i delete from Team it gives bellow Error
HTTP Status 500 - Request processing failed; nested exception is org.springframework.dao.DataIntegrityViolationException:
Could not execute JDBC batch update; SQL [delete from Teams where teamID=?];
constraint [null];
nested exception is org.hibernate.exception.ConstraintViolationException:
Could not execute JDBC batch update
Upvotes: 0
Views: 2796
Reputation: 1
you are using hibernate method is wrong~! that code: "hibernate.update(sql);".
Upvotes: 0
Reputation: 4310
Since your table Teams
has a one to one mapping to table Releases
, the exception clearly shows that you are violating an integrity constraint. Your query
delete from teams where id=?
tries to delete the record from table Teams
, but since you have a mapping to Releases
, you will first need to delete the referred row with teamID
in table Releases
and then delete the corresponding row from Teams
table.
Upvotes: 0
Reputation: 1688
First you need to delete all the records from Releases that has reference to Team you need to delete, and then the Team.
or use
@OneToMany(orphanRemoval=true)
Upvotes: 2