tags:

views:

10

answers:

1

Hello,

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 how I can get rid of this behavior.

Ralf

A: 

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

Ralf