These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Problem with ManyToMany relation
PostPosted: Sun May 17, 2009 6:47 am 
Newbie

Joined: Fri May 15, 2009 12:45 pm
Posts: 1
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,


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.