Zcon
Zcon

Reputation: 153

Cannot Delete a row from my table

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

Answers (3)

user2991122
user2991122

Reputation: 1

you are using hibernate method is wrong~! that code: "hibernate.update(sql);".

Upvotes: 0

user2339071
user2339071

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

Sandhu Santhakumar
Sandhu Santhakumar

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

Related Questions