开发者

Hibernate annotation unnecessary delete and insert

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜