I'm trying to implement Many-to-many relation using Hibernate and MySQL DB. I have class User:
@ManyToMany(fetch = FetchType.LAZY)
@JoinTable(name = "users_nodes",
joinColumns = {@JoinColumn(name = "user_id")},
inverseJoinColumns = {@JoinColumn(name = "node_id")})
private List<Node> nodeList;
and class Node:
@ManyToMany(mappedBy = "nodeList", cascade = CascadeType.ALL)
private List<User> users;
When I'm trying to save a new Node to DB(which already have user in it) it successfully add new entity to "nodes" table, but relation table "users_nodes" is empty.
This is the way I save Node entity:
@Override @Transactional
public void persist(Node entity) {
getCurrentSession().save(entity);
}
Thanks for your help!