Hello.
I wondered which is the right way to insert records in a medial table, that is, a table for many-to-many associations.
It exists in the collection mappings.
In the java-code it is just a Set, that get be fetched from one of the objects.
If we want to add a record to this medial table (for example users_favorites, that is - links 'users' and 'favorites' for a many-to-many association)?
Code:
Set favorites = user.getFavorites();
favorites.add(newFavorite); // Adds the new entry?
user.setFavorites(favorites);
session.saveOrUpdate(user);