Suppose a CRUD application in JSF. The user edits the Student and clicks on "Delete attach" button. Then, the action do: student.setAttach(null). After, the user clicks on the "Save record" button. Now, how can I know what attach was referenced? I will need keep the reference.
The Attach is a weak entity. So, I would not like to implement a Attach Dao to delete the entity manually. See the code that I need to implement for every entity that has an association that can be deleted:
Code:
public void deleteAttach() {
Attach attachToBeDeleted = getPersistentObject().getAttach();
getPersistentObject().setAttach(null);
}
public String saveRecord() {
...
if (attachToBeDeleted != null) {
attachDao.makeTransient(attachToBeDeleted );
}
}
Is suck write this kind of code everywhere.
Why Hibernate can't delete the attach entity if the association was deleted?
Thank you!