Here is my User object:
I get a User(s) from the database:
I update it/them:
And then I save it:
And there is my problem. Everything looks fine until, When I debug the Server, the User (u) looks like it works, but when I refresh it, it reverts back to whatever is in the database before the attempted changes. I did try using merge(u) instead of persist(u), but it made no difference! I thought that if the entity already existed, you NEEDED to call merge().
Note that the user, permissions, dataloggers, columnheadings, etc all exist. All I am doing is trying to make the relationship between them.
Any suggestions?
OK - I'm an idiot. I only updated one way of the many-to-many relationships. You need to update both ends :
u.getDataloggerCollection().clear();
for (
String userLogger : user.loggers) {
for (Datalogger availLogger :loggerList) {
if (userLogger.equals(availLogger.getName())) {
u.getDataloggerCollection().add(availLogger);
/** NEED TO ADD THIS: **/
availLogger.getUsers.add(u);
break;
}
}
}