search

Home  >  Q&A  >  body text

java - In hibernate bidirectional many-to-many relationship, how to automatically update the intermediate table when one of the parties is modified?

In the many-to-many relationship between the employee table and the department table, when setting up the department collection through the employee table, it was found that the intermediate table automatically deleted records, but no updated data was inserted, as follows:

refer to:

Employee table:

Department table:

Please tell me how to update the department set field of the employee table through the set method of the employee table in the following code, and at the same time automatically update the intermediate table, that is, the intermediate table should insert new records after deleting records.

阿神阿神2775 days ago607

reply all(2)I'll reply

  • 伊谢尔伦

    伊谢尔伦2017-05-17 10:05:35

    When asking questions, it is best not to take screenshots of the code, but to post the source code so that others can view and simulate it

    reply
    0
  • 仅有的幸福

    仅有的幸福2017-05-17 10:05:35

    I don’t know if this is correct, I think your problem is that you should add cascade or inverse cascade in the configuration file

    reply
    0
  • Cancelreply