title: Hibernate user_roles table will not update when using ManyToOne relationship
body: <p>I have 3 tables, User, Role, and User_role. User has a OneToMany relationship mapped by "user" with a CascadeType.Merge and user_role has 2 ManyToOne Relationships with cascadeTypes.All however the user_table never populates with data when running hibernate. Instead values are only populated in the user and role tables, but never the user_role table.</p>
  
  <p>User Table Definition</p>
  
  <pre><code>@Id
  @GeneratedValue(strategy = GenerationType.AUTO)
  @Column(name="Id", nullable=false, updatable = false)
  private Long id;
  
  private String username;
  private String password;
  private String firstName;
  private String lastName;
  
  private String email;
  private String phone;
  private boolean enabled = true;
  
  @OneToMany(mappedBy = "user", cascade=CascadeType.MERGE, fetch = 
  FetchType.EAGER)
  @JsonIgnore
  private Set&lt;UserRole&gt; userRoles = new HashSet&lt;&gt;();
  </code></pre>
  
  <p>UserRole Table:</p>
  
  <pre><code>@Entity
  @Table(name="user_role")
  public class UserRole implements Serializable {
  private static final long serialVersionUID = 890345L;
  
  @Id
  @GeneratedValue(strategy = GenerationType.AUTO)
  private long userRoleId;
  
  @ManyToOne(fetch = FetchType.EAGER, cascade=CascadeType.ALL, 
  optional=false)
  @JoinColumn(name = "user_id")
  private User user;
  
  @ManyToOne(fetch = FetchType.EAGER, cascade=CascadeType.ALL,  
  optional=false)
  @JoinColumn(name = "role_id")
  private Role role;
  
  public UserRole () {}
  
  public UserRole (User user, Role role) {
      this.user = user;
      this.role = role;
  }
  
  public long getUserRoleId() {
      return userRoleId;
  }
  
  public void setUserRoleId(long userRoleId) {
      this.userRoleId = userRoleId;
  }
  
  public User getUser() {
      return user;
  }
  
  public void setUser(User user) {
      this.user = user;
  }
  
  public Role getRole() {
      return role;
  }
  
  public void setRole(Role role) {
      this.role = role;
  }
  
  }
  </code></pre>
  
  <p>Call To userRepository.save() in userServiceImpl that is called from a commandLine Runner.</p>
  
  <pre><code>@Service
  </code></pre>
  
  <p>public class UserServiceImpl implements UserService {</p>
  
  <pre><code>private static final Logger LOG = LoggerFactory.getLogger(UserSecurityService.class);
  
  
  @Autowired
  private UserRepository userRepository;
  
  @Autowired
  private RoleRepository roleRepository;
  
  
  // Indicates a  Database Transaction
  @Transactional
  public User createUser(User user, Set&lt;UserRole&gt; userRoles) {
      User localUser = userRepository.findByUsername(user.getUsername());
  
      if(localUser != null) {
          LOG.info("User with username {} already exist. Nothing will be done. ", user.getUsername());
      } else {
  
  
          for (UserRole ur : userRoles) {
              roleRepository.save(ur.getRole());
          }
  
          Set&lt;UserRole&gt; currentRoles =user.getUserRoles();
  
          currentRoles.addAll(userRoles);
          user.setUserRoles(currentRoles);
  
  
          localUser = userRepository.save(user);
      }
  
      return localUser;    
  }
  </code></pre>
  
  <p>}</p>
  
  <p>Main Class Run()</p>
  
  <pre><code>    public void run(String... args) throws Exception {
      User user1 = new User();
      user1.setFirstName("John");
      user1.setLastName("Adams");
      user1.setUsername("j");
      user1.setPassword(SecurityUtility.passwordEncoder().encode("p"));
      user1.setEmail("JAdams@gmail.com");
      Set&lt;UserRole&gt; userRoles = new HashSet&lt;&gt;();
      Role role1 = new Role();
      role1.setRoleId(1);
      role1.setName("ROLE_USER");
      userRoles.add(new UserRole(user1, role1));
  
      userService.createUser(user1, userRoles);
  }
  </code></pre>