Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Silently ignored remove()

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.

like image 872
Maksim Gumerov Avatar asked Jan 06 '23 19:01

Maksim Gumerov


1 Answers

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.

like image 192
Dragan Bozanovic Avatar answered Jan 31 '23 09:01

Dragan Bozanovic