I'm currently trying to create a ManyToMany relation on a Stripes project with Hibernate. I have both Projects and Users, which are connected with a ManyToMany relationship.
I've created the association on my project entity with the following code:
Code:
@ManyToMany
@JoinTable(
name = "projects_users",
joinColumns = @JoinColumn(name = "project_id"),
inverseJoinColumns = @JoinColumn(name = "user_id")
)
private Set<User> users = new HashSet<User>();
Since I want it to be bidirectional, I've added the following annotation to the User entity:
Code:
@ManyToMany(mappedBy = "users")
private Set<Project> projects = new HashSet<Project>();
The table is properly created when I run my application. However, whenever I try to add users to projects, I get the following exception:
Code:
org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: pt.up.fe.kernelpanic.reuse.entities.Project.users, no session or session was closed
I'm new to Hibernate and Java web programming, so I'm a bit clueless to why this isn't working.
Thanks,