How do you initialize your components? I think you want to give your labels
etc PropertyModels on the LoadableDetachableModel, so with every new
request, a fresh model object will be grabbed from your service.

Does the page work correctly in some circumstances? If not, you may have
issues with your session or transaction demarcation. The session should
still be active while wicket is rendering the page and components.

On Thu, Jun 25, 2009 at 10:55 AM, jpalmer1026 <jpalmer1...@mchsi.com> wrote:

>
> How do you recommend holding the model in the page? In other words, what is
> the alternative code to  "this.user = (EzdecUser)userModel.getObject();"?
>
>
> Martin Sachs wrote:
> >
> > hi
> >
> > you used   "this.user = (EzdecUser)userModel.getObject();" This would
> > hold in page and not initialized on next request.
> > You have to hold the model in the page.
> >
> > We have also found an alternative way. You can write a simple Aspect
> > with AspectJ to reinit all proxies. This can easily done with
> > hibernateSession.lock(NONE).
> > Create pointcuts to each getter which is returning a proxy and init the
> > proxies.
> >
> > Martin
> >
> >
> >
> >
> > jpalmer1...@mchsi.com schrieb:
> >> I am getting an "org.hibernate.LazyInitializationException - could not
> >> initialize proxy - no Session" exception when I try to load an object
> >> stored in session. I understand but I am not certain about how to fix
> >> it with Wicket. In reviewing the Wicket In Action book, it looks like
> >> the way to handle this is to use a LoadableDetachableModel, which I
> >> tried. The model is as follows:
> >>
> >> public class DetachableUserModel extends
> >> LoadableDetachableModel<EzdecUser> {
> >>
> >>     @SpringBean
> >>     private ISecurityService securityService;
> >>
> >>     private final String email;
> >>
> >>     public DetachableUserModel(EzdecUser u) {
> >>         this(u.getEmail());
> >>     }
> >>
> >>     public DetachableUserModel(String email) {
> >>         if (email == null) {
> >>             throw new IllegalArgumentException();
> >>         }
> >>         this.email = email;
> >>         System.out.println("email is " + email);
> >>         InjectorHolder.getInjector().inject(this);
> >>     }
> >>
> >>     @Override
> >>     public int hashCode() {
> >>         return email.hashCode();
> >>     }
> >>
> >>     @Override
> >>     public boolean equals(final Object obj) {
> >>         if (obj == this) {
> >>             return true;
> >>         } else if (obj == null) {
> >>             return false;
> >>         } else if (obj instanceof DetachableUserModel) {
> >>             DetachableUserModel other = (DetachableUserModel) obj;
> >>             return email.equals(other.email);
> >>         }
> >>         return false;
> >>     }
> >>
> >>     @Override
> >>     protected EzdecUser load() {
> >>         EzdecUser u = securityService.findUserByEmail(email);
> >>         return u;
> >>     }
> >>
> >> }
> >>
> >> The relevant section of the code where I am using the model is as
> >> follows:
> >>
> >>  public UpdateUserProfilePage() {
> >>         this(EzdecSession.getCurrentUser());
> >>     }
> >>
> >>     public UpdateUserProfilePage(EzdecUser user) {
> >>         this(new DetachableUserModel(user));
> >>     }
> >>
> >>     private UpdateUserProfilePage(DetachableUserModel userModel) {
> >>         this.user = (EzdecUser)userModel.getObject();
> >>         setup();
> >>     }
> >>
> >> Anyone have any suggestions on how I can fix this?
> >>
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
> > For additional commands, e-mail: users-h...@wicket.apache.org
> >
> >
> >
>
> --
> View this message in context:
> http://www.nabble.com/Hibernate-LazyInitializationException-tp24204249p24204789.html
> Sent from the Wicket - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
> For additional commands, e-mail: users-h...@wicket.apache.org
>
>

Reply via email to