Once upon a time… I haved a problem with setting entities which are connected with many-to-many relationship.
I in both enitites I just declared one field is type of Set<>, with standart code:
But when I started setting this relation. Nothing was in the database.
Ok, lets go to the solution. With many-to-many relationship, you should change not field with @ManyToMany annotation. You should use association entity (OrderItem).
I have three entities, with many-to-many relationship (Order, Item, OrderItem).
After that you can set relationship like that:
And everything should be work properly.