1
I have a relationship ManyToMany
amid users
and profiles
mapped with Hibernate
:
user:
id
name
profile:
id
profile_name
user_profile:
user_id
profile_id
The mapping is done as follows:
User:
@ManyToMany(fetch = FetchType.EAGER)
private List<Profile> profiles = new ArrayList<>();
Profile
@ManyToMany(fetch = FetchType.EAGER, mappedBy = "profiles")
private List<User> users= new ArrayList<>();
So far it is quiet, all entities are created in the bank and I already have some data.
Currently I make the method delete in this way:
public void excluir(T entity) {
Session session = HibernateUtil.getSessionFactory().openSession();
Transaction transacao = null;
try {
transacao = session.beginTransaction();
session.delete(entity);
transacao.commit();
} catch (RuntimeException e) {
if (transacao != null)
transacao.rollback();
throw e;
} finally {
session.close();
}
}
My question is this::
How do I delete an item from the relationship
user_profile
? I don’t want to exclude theUser
nor theProfile
, only one item of the relationship between the two.