Fwiw Mathias, here is a model class that I like to use in the project I work
on:

/**

 * LDM for domain objects. Detaches (nulls) object after each request.

 */

public class DomainObjectModel<T extends DomainObject>
extendsLoadableDetachableModel {


  @SpringBean

  private GenericHibernateDao dao;


  private final Class<T> domainClass;


  private final Long id;


  /**

   * Construct with class and id; next invocation will trigger loading the

   * object with the id.

   *

   * @param domainClass

   * @param id

   */

  public DomainObjectModel(Class<T> domainClass, Long id) {

    if (domainClass == null) {

      throw new IllegalArgumentException("domainClass may not be null");

    }

    if (id == null) {

      throw new IllegalArgumentException("id may not be null");

    }

    SpringInjector.injectDependencies(this);

    this.domainClass = domainClass;

    this.id = id;

  }


 /**

  * Construct with domain object instance, which will be reused for the

  * current request.

  *

  * @param domainObject

  */

  @SuppressWarnings("unchecked")

  public DomainObjectModel(T domainObject) {

    super(domainObject);

    if (domainObject == null) {

      throw new IllegalArgumentException("domainObject may not be null");

    }

    SpringInjector.injectDependencies(this);

    this.domainClass = (Class<T>)

    HibernateProxyHelper.getClassWithoutInitializingProxy(domainObject);

    this.id = domainObject.getId();

  }


  @Override

  public boolean equals(Object obj) {

    return Objects.equal(obj, getObject());

  }


  @Override

  public int hashCode() {

    return Objects.hashCode(getObject());

  }


  /**

   * @see org.apache.wicket.model.LoadableDetachableModel#load()

   */

  @Override

  protected Object load() {

    return dao.load(domainClass, id);

  }


  @SuppressWarnings("unchecked")

  @Override

  public T getObject() {

    return (T) super.getObject();

  }

}


Where DomainObject is:


/**

 * Should be implemented by all normal domain objects.

 */

public interface DomainObject extends Serializable {


 /**

  * @return The id of the domain object

  */

  Long getId();

}


Might not be what you want, but it is probably a good idea to make such a
model class that you can reuse throughout your project(s).


Probably also can be improved with Wicket 1.4, but I didn't get to look at
that yet :-)


Eelco


On Sun, May 4, 2008 at 10:11 AM, Igor Vaynberg <[EMAIL PROTECTED]>
wrote:

> you still have something misconfigured or you are not using detachable
> models where you should. ive built plenty of hibernate+spring+wicket
> apps to know that it works just fine and is pretty easy to do. if you
> want you can post a quickstart that demonstrates your problem and
> someone might be able to help you.
>
> -igor
>
>
> On Sun, May 4, 2008 at 10:01 AM, Mathias P.W Nilsson
> <[EMAIL PROTECTED]> wrote:
> >
> >  I have session in view filter but still gets LazyLoadingException even
> if I
> >  use detached models! Ahhh...
> >
> >  Solved it temporarily by using Eager fetch but this is going to end up
> bad
> >  if everything is eager.
> >  --
> >  View this message in context:
> http://www.nabble.com/How-to-avoid-Lazy-loading-exception-tp17040941p17048739.html
> >
> >
> > Sent from the Wicket - User mailing list archive at Nabble.com.
> >
> >
> >  ---------------------------------------------------------------------
> >  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