class MySession extends WebSession {
  private Long userId;
  private transient User user;

  public SYNCHRONIZED void setUser(User user) {
    user=user;
    userId=(user==null)?null:user.getId();
  }

  public SYNCHRONIZED void getUser() {
      if (user==null) {
        if (userId!=null) {
          user=getHibernateSession().load(User.class, userId);
         }
      }
      return user;
   }

   protected void onDetach() {
        user=null;
   }
}

-igor

On Jan 7, 2008 11:11 AM, Dan Kaplan <[EMAIL PROTECTED]> wrote:
> Is there an example somewhere that shows how to do this?  Or can someone
> paste a snippet here of how to do this?  I assume a lot of webapps have the
> concept of a User object.
>
> -----Original Message-----
> From: Martijn Dashorst [mailto:[EMAIL PROTECTED]
> Sent: Saturday, January 05, 2008 5:17 AM
> To: users@wicket.apache.org
> Subject: Re: Wicket Session and threading
>
>
> If you use hibernate, this is not recommended... An entity can only be
> part of one Hibernate Session, and storing the instance in the wicket
> session will share it across threads, and hence you'll get hibernate
> exceptions.
>
> Note that this may not be only a problem in Hibernate, but can also be
> a problem in other db frameworks.
>
> So do what Johan described and you will be safe...
>
> Martijn
>
> On Jan 5, 2008 3:54 AM, Eelco Hillenius <[EMAIL PROTECTED]> wrote:
> > On Jan 5, 2008 5:15 AM, Dan Kaplan <[EMAIL PROTECTED]> wrote:
> > > Yeah that makes sense.  Since we're sorta on the topic, I thought I
> would
> > > ask this question.  As the User object goes from being initially
> registered
> > > to its profile being edited, how does one update the User in the session
> and
> > > the db simultaneously?
> > >
> > > Here's a scenario:  A user registers with your website and later adds a
> > > signature that is to show up on every post he makes.
> > >
> > > Do you add an instance of a UserService to your WebSession and then have
> > > this in it:
> > >
> > > private User user;
> > >
> > > public synchronized void setUser(User updatedUser) {
> > >   userService.updateUser(updatedUser);
> > >   this.user = updatedUser;
> > > }
> > >
> > > public synchronized User getUser() {
> > >   return this.user;
> > > }
> > >
> > > ?  Cause I've been doing something like that.  Is there a better way to
> go
> > > about this?
> >
> >
> > Looks fine to me.
> >
> > Eelco
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> >
> >
>
>
>
> --
> Buy Wicket in Action: http://manning.com/dashorst
> Apache Wicket 1.3.0 is released
> Get it now: http://www.apache.org/dyn/closer.cgi/wicket/1.3.0
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to