Hi all,
In order to map a many to many with association class,
I take a closer look to the implementation provided within
Admin app application:
I noticed the following at runtime :
public UserRole addRole(Role role) {
if ( getRoles().indexOf(role)>=0 ) {
throw new RuntimeException("role already assigned");
}
getRoles().add(role);
role.getUsers().add(this);
UserRole ur = new UserRole(this, role);
getUserRoles().add(ur);
return ur;
}
getRoles().add(role) used an java.util.Arraylist and
role.getUsers().add(this); use an net.sf.hibernate.collection.Bag
and following exception occured :
13:48:02,610 ERROR LazyInitializationException:25 - Failed to lazily initialize a collection - no session or session was closed
net.sf.hibernate.LazyInitializationException: Failed to lazily initialize a collection - no session or session was closed
at net.sf.hibernate.collection.PersistentCollection.initialize(PersistentCollection.java:214)
at net.sf.hibernate.collection.PersistentCollection.write(PersistentCollection.java:84)
at net.sf.hibernate.collection.Bag.add(Bag.java:281)
If someone has any idea,
Thanks in advance.
zoeeoz.
|