Bulk Insert Many-to-Many Relationship

Colin M

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?

JB Nizet

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.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Bulk Create objects with Many to Many Relationship in Django

From Dev

coreData insert to to many relationship

From Dev

coreData insert to to many relationship

From Dev

INSERT/DELETE examples in a many-to-many relationship

From Dev

How to insert data in many to many relationship

From Dev

PostgreSQL insert array many-to-many relationship

From Dev

INSERT statement for One to Many relationship

From Dev

Laravel insert in one to many relationship

From Dev

How to Insert, Update, Delete in a one to many relationship?

From Dev

it is possible to insert one to many relationship to database together?

From Dev

Laravel insert record with one to many relationship

From Dev

MySQL - How to insert into table that has many-to-many relationship

From Dev

Insert operation with many-to-many relationship using EF

From Dev

How to insert into associative table in many to many relationship by Hibernate?

From Dev

Doctrine + Zend Framework 2: Insert array of data in a many to many relationship

From Dev

Is this a many-to-many relationship?

From Dev

Many to Many relationship in Ecto

From Dev

Many to many relationship and MySQL

From Dev

implementing a many to many relationship

From Dev

Many to many relationship optimization

From Dev

many to many powerpivot relationship

From Dev

Sqlalchemy many to many relationship

From Dev

Laravel - Many to Many relationship

From Dev

Many to many relationship with itself

From Dev

Many to Many Relationship in Cakephp

From Dev

Searching many to many relationship

From Dev

A many to many relationship

From Dev

Mysql Many to Many relationship

From Dev

What is a many to many relationship?

Related Related

HotTag

Archive