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

From: Andrus Adamchik (andru..bjectstyle.org)
Date: Tue Nov 29 2005 - 07:59:07 EST

  • Next message: Mike Kienenberger: "Re: Dates inserted into Oracle do not have Minutes / Seconds?"

    > if (dataContext == null)
    > {
    > log.info ("Current thread has NULL DataContext- Creating.") ;
    > dataContext = DataContext.createDataContext() ;
    > DataContext.bindThreadDataContext(dataContext) ;
    > }

    The code above will NOT do the right thing. Instead you may use a new
    ServletUtil class to make sure the context is not only bound to the
    thread, but also to the current session:

           if (dataContext == null)
           {
              log.info ("Current thread has NULL DataContext- Creating.") ;

              // how you get a hold of HttpSession - I don't know...
              // I know next to nothing about HiveMind
              dataContext = ServletUtil.getSessionContext(session);
              DataContext.bindThreadDataContext(dataContext) ;
           }

    Still consider that WebApplicationContextProvider would always create
    a new session if one doesn't yet exist. So I don't understand why
    would null thread DataContext ever occur. Maybe you should remove the
    try/catch and let the exception be thrown and then investigate why it
    happens?

    Andrus



    This archive was generated by hypermail 2.0.0 : Tue Nov 29 2005 - 07:59:09 EST