Re: Please help: retrieval and proper usage of per thread DataContext

From: Andrus Adamchik (andru..bjectstyle.org)
Date: Wed Nov 30 2005 - 11:52:52 EST

  • Next message: Mike Kienenberger: "Re: Please help: retrieval and proper usage of per thread DataContext"

    This will work only if

      (a) you use it consistently and there is no other code that sticks
    a DataContext in a session and
      (b) you app carries no Cayenne-related state between requests (such
    as session DataObjects).

    I believe this was not the case in Joseph's app, judging from the
    problems that he had.

    Andrus

    On Nov 30, 2005, at 7:46 PM, Joshua Pyle wrote:
    > Just incase this helps, this is all I do when getting a datacontext.
    >
    > public DataContext getDataContext() {
    > DataContext context = null;
    > try {
    > context = DataContext.getThreadDataContext();
    > } catch (IllegalStateException ex) {
    > // Bind the DataContext
    > context = DataContext.createDataContext();
    > DataContext.bindThreadDataContext(context);
    > }
    > return context;
    > }
    >
    > This is working great and essentially just gives me a DataContext that
    > lives only during the request. I've found this is a great aproach for
    > web based applications.
    >
    > --
    > Joshua T. Pyle
    > Go has always existed.



    This archive was generated by hypermail 2.0.0 : Wed Nov 30 2005 - 11:52:55 EST