Thanks for clarifying this me.
My next question is, how can I make this piece of code more transaction friendly?
let's assume that during one method call to modifyTest(), the deleteTest() completes successfully, but the addTest() throws an exception. In this case, because I manually flushed the entityManager after deleteTest(), this record is removed from database although the new insertion does not work. How can I make sure these two are inside one atomic transaction? So if there is a problem with the new data, the old data should not be removed.
I understand that entityManager.merge is probably a better approach to update a database record, but I have to use this delete/add combination for some other business reasons.
Thanks a lot for your help!
Joanne
|