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

Reply via email to