开发者

Hibernate annotation unnecessary delete and insert

开发者 https://www.devze.com 2023-01-18 23:50 出处:网络
I have a class A which has set of class B. class A and class B has their own table. When i insert class A it also insert class B. Wh开发者_运维百科en i update class B, Hibernate deletes everything fro

I have a class A which has set of class B. class A and class B has their own table. When i insert class A it also insert class B. Wh开发者_运维百科en i update class B, Hibernate deletes everything from class B which belongs to that instance of A and then insert all values in current set B. I want that if only 2 new values are added in set b, then it only insert that 2 values and leave the rest. I try saveorupdate but it is not working.


Hibernate usually behaves like this when you clear the set before adding the items, or when you replace the set with a new instance. In both cases, it deletes the items in one sql statement. It is basically an optimization when the list had been built up from scratch.

Make sure that you only remove items which you don't need anymore.

0

精彩评论

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