i want to delete a row and cascade all foreign keys in hibernate i am new to hibernate and i want to know if there's a method to delete an entity>> session.delete(); like the session.save and session.update methods in hibernate?
1 Answer
Yes, hibernate's Session has delete(entity) method.
If you want to cascade dependencies, you'd have to set @*ToMany(cascade=CascadeType.DELETE)
5 Comments
user353682
where to set this annotation on the primary key or the foreign key ?
Bozho
not on the primary key. I wouldn't call it "on the foreign key", but yes.
Anto Varghese
If I want to delete only a single record, what is the way?
Bozho
@Antoops - the delete method.
David García
This related question is very interesting: stackoverflow.com/questions/13210638/hibernate-delete-query