1

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 1

1

Yes, hibernate's Session has delete(entity) method.

If you want to cascade dependencies, you'd have to set @*ToMany(cascade=CascadeType.DELETE)

Sign up to request clarification or add additional context in comments.

5 Comments

where to set this annotation on the primary key or the foreign key ?
not on the primary key. I wouldn't call it "on the foreign key", but yes.
If I want to delete only a single record, what is the way?
@Antoops - the delete method.
This related question is very interesting: stackoverflow.com/questions/13210638/hibernate-delete-query

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.