开发者

Hibernate: Why does a change of bag lead to strange ADDs and DELETEs in the database?

I have an n:m-association between the two classes User and Role, implemented as a bag with lazy="extra". The association is stored an an association table sind a user can have many roles and a role can be associated with many users.

Now when I add a new role to a user, hibernate emmits sql code that first removes all entries in th eassociation table an then adds them all again plus the new association.

I'd like to know why this happens and开发者_StackOverflow社区 how I can get rid of this behavior.

Ralf


I've found the solution myself: Hibernate bags always first delete alle entreis and then rebuild the new state. If you use a set, the association is properly maintained.

See hibernate manual, Improving Performance

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜