Hi Florian, When constructing your CheckBoxMultipleChoice, use a PropertyModel(userModel, "roles") for the "model" argument, and a new LDM that returns a list of all available UserRoles for the "choices" argument. Unless you need UserRole to be serializable for some other reason, I'd remove its Serializable interface so you can catch the entity serialization as soon as it happens-- you're right that that's the root of your trouble.
Dan On Mon, Sep 12, 2011 at 3:17 AM, Florian B. <[email protected]>wrote: > I've got a form which is used to create and edit users for my application. > In > this form predefined roles which are loaded from the database can be > assigned to the user. Users and roles are associated using a many to many > relation ship which loads lazy on both ends. To assign the roles a > CheckBoxMultipleChoice is used. > > Now when I assign a role to a user I run into some lazy loading exception > issues. The problem is that the roles are loaded in the request that > renders > the form. After altering the user's roles and hitting the save button a new > request is started. In this request the user object is saved with the new > roles. To do this correct related to the many to many association it's not > enough to add the roles only to the user's roles set but also add the user > to the role's user set. And this is where the exceptions happens. When > calling getUsers() on the roles object the LazyInitializationException > occurs as the roles where loaded in an earlier request when the form was > loaded. > > I'm already using the LDM for the user object. I think using it for the > roles could also solve the problem, but I'm a little bit confused how to > use > it together with the CheckBoxMultipleChoice component as the items which > could be selected are passed as a simple List and not as a model. > > -- > View this message in context: > http://apache-wicket.1842946.n4.nabble.com/LazyInitializationException-with-CheckBoxMultipleChoice-tp3806997p3806997.html > Sent from the Users forum mailing list archive at Nabble.com. > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [email protected] > For additional commands, e-mail: [email protected] > >
