I have an entities defined as:
class Group {
// some irrelevant fields
@ManyToMany(targetEntity=User.class)
private List<User> users;
}
class User {
// some irrelevant fields
@ManyToMany(targetEntity=Group.class)
private List<Group> groups;
}
In my interface, I'm trying to provide a way to add users to a group in a sort of bulk-entry form. Is there a way to allow the insertion of a new many-to-many entry, without having to load the entire collection of users in a group first?
One of the side has to be the inverse side, using mappedBy
. You just need to update the owner side.
So if you make User
the owner side, you just need to add the group to the user.
If that is not sufficient, then consider using SQL.
Also, targetEntity
is redundant with the generic type of the list. You don't need it.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments