Is there a way to detect the objects affected by a JPA cascade persist call?

82 Views Asked by At

Say you have an Entity called ContainerType1 and a child called Thing and you have a one to many relationship between ContainerType1 and Thing. The ContainerType1 has a set of Thing. And say it's not a 2 way relationship, so Thing is not aware of the object it is contained in. Later I may want a ContainerType2 and ContainerType3. I want all of my code for Thing to be modularized and not aware of it's container. If, on my client side, I fire a call to the server to delete an instance of Thing, I want this to cascade to my various containers.

So, is there a way to make a call to persist or delete or whatever operation and then get the result of what was touched by a cascade? In this case, on a call to delete a Thing, I'd like to then say, okay what containers had this removed from their sets? I'm using Hibernate via JPA and would prefer a JPA only solution but I have no idea if you can even do this in either the JPA or Hibernate world. The idea here is to fire something back to the client saying which containers to refresh because they lost a Thing. It could be 0..n containers.

More broadly, can you tell hibernate/JPA to do something and then say, "great, that was all nice and automatic, now tell me what you just did, please"?

1

There are 1 best solutions below

1
On

Are the queries useful for your purposes?

<property name="show_sql">true</property>
<property name="format_sql">true</property>
<property name="use_sql_comments">true</property>

See also How To Display Hibernate Sql Parameter Values – Log4j.