Re: Best Practices for Retrieving DataContexts

From: Eric Schneider (eri..entralparksoftware.com)
Date: Sun Jun 27 2004 - 22:31:59 EDT

  • Next message: Andrus Adamchik: "Re: Best Practices for Retrieving DataContexts"

    Scott,

    Using a shared DataContext is totally reasonable in some scenarios. I
    think this approach is a slam dunk for read only applications.

    If your applications aren't read only, the DataContext per session is
    probably the preferred approach. Though, I've considered trying
    something different myself. There may be ways to shared a single
    DataContext and synchronize updates and inserts.

    I'm wondering if Andrus has an opinion on this approach. He'd be able
    to point out the gotchas.

    e.

    On Jun 27, 2004, at 2:51 PM, Scott McClure wrote:

    > In the documentation, the suggested method for retrieving a
    > DataContext is to
    > store a DataContext in the HttpSession. While this works well, I do
    > not want to
    > pass my HttpSession into the DAO layer of my application, since it is
    > not
    > currently part of the DAO interfaces. At the same time, I do not want
    > to
    > retrieve a new DataContext for every method call. In Spring-Hibernate
    > integration, this problem is solved by tying the Hibernate Session to
    > the
    > thread, and calling another SessionUtil class to either retrieve a
    > session from
    > the thread or create a new one. I do not think this will work as well
    > in
    > Cayenne due to the differences in Hibernate Sessions and Cayenne
    > DataContexts.
    > What is the best way to deal with this? Basically, the underlying goal
    > is to
    > implement a Cayenne DAO that is stateless and has no HttpSession
    > passed in,
    > without causing unnecessary overhead with too many DataContexts.
    >
    > In general, I would be interested to hear how people deal with
    > DataContexts in a
    > web application if it is different than the
    > one-datacontext-per-session method.
    >
    > oh, btw, awesome project!
    >
    > Scott
    >



    This archive was generated by hypermail 2.0.0 : Sun Jun 27 2004 - 22:33:35 EDT