JPA ManyToMany in case of users and groups?

后端 未结 1 1434
傲寒
傲寒 2021-01-16 18:01

Same question here, but it didn\'t help me

\"DB:

I\'ve got thr

相关标签:
1条回答
  • 2021-01-16 18:39

    I got it working. My code was messy and I cleaned it out and it helped. I am not so sure why updating the groups-table inserts a new user to Users-table, but it is ok to me. At first I updated groups-table and inserted user to users-table and I always got an exception that there is the pk already (username is the pk). So it made two inserts to users-table, but now it's working perfectly. No more lines to groups-table just to joint-table and users-table.

    // Add current new user to the customer-group
                usersCollection.add(currentUser);
                customerGroup.setUsersCollection(usersCollection);
    
                // Updating the group using GroupsController, THIS INSERTS USER TO USERS-table as well!!
                groupsC.updateGroup(customerGroup);
    
    0 讨论(0)
提交回复
热议问题