yet another many-to-many Hibernate questions. I have the simplest possible many-to-many mapping as follows:
@Entity
public class Strategy implements Serializable
First of all, your mapping is wrong. One side of the association must be the owner side, and define the mapping of the association. The other must be the inserse side, and just use the mappedBy attribute:
@ManyToMany(fetch = FetchType.EAGER, mappedBy = "groups")
private Set strategies = new HashSet();
Second, you should really avoid EAGER fetching on a toMany association, and particularly on both sides: this will force Hibernate to load all the associated entities recursively, and has a good chance to load all the rows of both tables in memory each time you load one row.
Now to your question:
If you want to delete everything from both tables, you first need to make sure that the join table is empty, else some rows in one of the tables will still be referenced by a row of the join table, and it will obviosuly fail. To do that, the best option in your case is to use a SQL query to delete everything from the join table before executing the two HQL queries you already have.