6 Replies Latest reply on Sep 1, 2005 12:21 PM by Emmanuel Bernard

    Many-toMany, Mysql trying to remove record

    George Taylor Newbie

      I have a table with a couple of many to many relationship set up:

      @ManyToMany(targetEntity = Role.class)
      @JoinTable(table = @Table(name = "GROUP_ROLE"), joinColumns = @JoinColumn(name = "GROUP_ID", referencedColumnName = "ID"), inverseJoinColumns = @JoinColumn(name = "ROLE_ID", referencedColumnName = "ID"))
      public List getRoles() {
      return roles;
      }
      @ManyToMany(targetEntity = User.class, mappedBy = "groups", cascade = {CascadeType.PERSIST, CascadeType.REFRESH, CascadeType.MERGE})
      public List getUsers() {
      return users;
      }


      when i try to remove the record, I am expecting it to remove the link record as well, which is enforced on the database. but instead i get an error.

      15:35:55,187 WARN [JDBCExceptionReporter] SQL Error: 1217, SQLState: 23000
      15:35:55,187 ERROR [JDBCExceptionReporter] Cannot delete or update a parent row: a foreign key constraint fails
      15:35:55,187 ERROR [AbstractFlushingEventListener] Could not synchronize database state with session
      org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update


      Can anyone please tell me what i am doing wrong. I would prefer not to take the constraints off the database as there is then the potential for data integrity issues.