Hibernate lazy fetching with Tapestry 3.x

The best references for Hibernate lazy fetching with Tapestry are Open Session in View pattern and, if you use Hibernate 3.1, generic DAO pattern with the latest Caveat Emptor constantly updated for Hibernate in Action 2nd edition, covering Hibernate 3.0 and 3.1

It is up to you to choose between session-per-request and session-per-conversation approach, but with a single servlet filter and generic DAO pattern you’ll have Hibernate transparently working with as few lines of code as possible, as far as I know.

For example, the only thing you’ll have to handle manually in case of session-per-request(which you want to do anyway to minimize the possibility of stale data) is (re)loading objects by IDs on every request, which can be achieved with pageBeginRender listener:

public abstract class PublicationViewPage extends BasePage implements
  PageRenderListener {
    ...
    public abstract void setPublicationID(long publicationID);
    public abstract void setPublication(Publication publication);
    ...
    public void pageBeginRender(PageEvent event) {
      if (!event.getRequestCycle().isRewinding()) {
        PublicationDAO publicationDAO = DAOFactory.DEFAULT.getPublicationDAO();
        Publication publication = publicationDAO.findById(getPublicationID(), false);
        setPublication(publication);
      }
    }
    ...
  }

assuming the ID of the data item to be displayed (Publication in my example) was set in the previous page:

public abstract class PublicationListPage extends BasePage implements
  PageRenderListener {
    ...
    public void selectPublication(IRequestCycle requestCycle) {
      Object[] parameters = requestCycle.getServiceParameters();
      Long publicationID = (Long)parameters[0];
      PublicationViewPage publicationViewPage = (PublicationViewPage)requestCycle.getPage("PublicationView");
      publicationViewPage.setPublicationID(publicationID);
      requestCycle.activate(publicationViewPage);
    }
    ...
  }