I took your advice and added a UserInfo variable to the RequestCycle [1].
Now my pages look for the UserInfo in the RequestCycle. If it's null, the
RequestCycle loads it from the ID in Session [2]. However, I still get the
LazyInitializationException when a page wants to access a collection from
userInfo [3], presumably because the Hibernate session was closed after the
Session loads the UserInfo. I thought that the OpenSessionInViewFilter was
supposed to keep the session open during the entire request, but apparently
I'm using it wrong.

[1] - public class WicketRequestCycle extends WebRequestCycle implements
Serializable {

    UserInfo userInfo;
    ...
    public UserInfo getUserInfo() {
        if (userInfo != null) return userInfo;
        userInfo = WicketSession.get().generateUserInfo();
        return userInfo;
    }
}


[2] - public class WicketSession extends AuthenticatedWebSession {

    @SpringBean(name = "userInfoDao")
    private UserInfoDao userInfoDao;

    private Long userInfoID;
    ...
    public UserInfo generateUserInfo() {
        if (userInfoID == null) return null;
        return personInfoDao.load(personInfoId, personInfoClass);
    }
}

[3] - public class UserRolesAuthorizer implements IRoleCheckingStrategy
{
    public boolean hasAnyRole(Roles roles)
    {
        PersonInfo personInfo = WicketRequestCycle.get().getPersonInfo();
        // THIS NEXT LINE THROWS THE ERROR, since it's trying to load
BasicUser
        return userInfo.getBasicUser().hasAnyRole(roles);
    }

}


On Mon, Aug 24, 2009 at 2:12 PM, Martijn Dashorst <
martijn.dasho...@gmail.com> wrote:

> Don't put the models in your session! Session access is not guaranteed
> to be confined to a single thread - multi window support, resources
> and such all attach the session to their own threads, making the
> session non-thread safe.
>
> Best option is to put the ID of your entities in your session object,
> and store the entities in your request cycle for request processing.
>
> Martijn
>
> On Mon, Aug 24, 2009 at 9:21 PM, Dane Laverty<danelave...@gmail.com>
> wrote:
> > I understand that a Hibernate-generated object needs to be kept in a
> > LoadableDetachableModel in order to avoid errors across requests. I also
> > understand that a LDM has to belong to a component in order for its
> detach
> > to be called at the end of a request. So what should I do with
> > Hibernate-generated objects that live in the session, specifically a
> > UserInfo object? Since the session doesn't have a model, how do I inform
> > Wicket to detach these models after each request?
> >
> > thanks,
> >
> > Dane
> >
>
>
>
> --
> Become a Wicket expert, learn from the best: http://wicketinaction.com
> Apache Wicket 1.4 increases type safety for web applications
> Get it now: http://www.apache.org/dyn/closer.cgi/wicket/1.4.0
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
> For additional commands, e-mail: users-h...@wicket.apache.org
>
>

Reply via email to