Quote:
I could: find the user and get the User object. Likewise for Role object. Update the role collection in User (u.getRoles().add(r), r.getUsers().add(u). Ask Hibernate to "update" both objects.
Thats exactly how you would do it.
Quote:
That sounds awfully expensive - a lot more than a simple SQL update?
If the classes are mapped with proxies, session.load() will not actually materialize the entity, just return the proxied instance.
You are not dealing with SQL, you are dealing with objects. Thats the whole point behind O/R mapping. I mean if you really want to directly issue SQL statements then do it. Or if you want to work with an object model instead, then use O/R layer.