I have a ManyToMany
relation between 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's cool, all entities are created in the database and I already have some data persisted in them.
I currently do the delete method 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:
How do I delete an item from the
user_profile
relation? I do not want excludeUser
andProfile
, only one item in the relationship between the two.