开发者

Why does lazy loaded child object not get deleted for detached parent object

开发者 https://www.devze.com 2023-04-13 02:03 出处:网络
I have a doubt about how JPA handles lazy initialization of child objects.If i have object A conta开发者_开发知识库ining a one-to-many with object B ( where B is lazy initialized) and i load object A(

I have a doubt about how JPA handles lazy initialization of child objects.If i have object A conta开发者_开发知识库ining a one-to-many with object B ( where B is lazy initialized) and i load object A( without accessing Set(B)) so that the Set(B) is null. Now if i detach A and then later merge(A), then why does JPA (in my case implemented by Hibernate) not delete the records for Set(B), given that Set(B) is now null? I have cascade=ALL set on Set(B).

I apologies if this is a trivial question or my understanding of the topic is not clear.


cascade=ALL isn't enough. You also need to delete orphans.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号