Silently ignored remove()

喜夏-厌秋 提交于 2019-11-26 09:14:30

问题


There is entity A referring (many-to-one) entity B, with inverse (mapped-by) reference from B to A. Also there is reference A to C and inverse reference C to A. When I issue entityManager.remove(A) then flush(), \"delete\" is not gerenated! But also there are no exceptions. It\'s just like no remove() was called at all. Why would that happen? If before remove() we extract A from reverse references B.listOfA and C.listOfA, \"delete\" is generated as expected.

Also note my another question where I came to conclusion that orphanRemoval not always works as expected. Now I am starting to suspect that maybe cascading worked well, but after that actual cascaded removal was \"swallowed\" like I described here.


回答1:


Take a look at this answer. Basically, JPA specification mandates that a removed entity becomes managed again if the persist operation is applied to it.

To verify that this is really happening, enable the trace log level for org.hibernate package and search for log entries like:

un-scheduling entity deletion ...

To avoid any unpredictable behaviour, it is recommended that references to removed entities are removed from all the other entity instances that are loaded the same session/transaction.



来源:https://stackoverflow.com/questions/34840903/silently-ignored-remove

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!