RE: BaseContext in servlet

From: Kuhns, John (jkuhn..imNTLS.com)
Date: Tue Jun 15 2010 - 14:41:56 UTC

  • Next message: Andrus Adamchik: "Re: DB2 stored procedure"

    Right, yes, the code I pasted was a little skewed after a frustrating run of attempts to resolve this, but I think I see my problem now. I am retooling as we speak.

    -----Original Message-----
    From: Michael Gentry [mailto:mgentr..asslight.net]
    Sent: Tuesday, June 15, 2010 10:31 AM
    To: use..ayenne.apache.org
    Subject: Re: BaseContext in servlet

    What happens if you omit this line?

    BaseContext.bindThreadObjectContext(ctx);

    On Tue, Jun 15, 2010 at 10:16 AM, Kuhns, John <jkuhn..imntls.com> wrote:
    > I am attempting to set a reference to a pojo containing some user info for use during updates/inserts. On reading the documentation early on, 3.0RC1 or so, I believed I could use setUserProperty and the context would be reused within a given session. However it appears that BaseContext.getThreadObjectContext() does not return the same context ever.
    >
    > In my web.xml I have:
    >        <filter>
    >                <filter-name>CayenneFilter</filter-name>
    >                <filter-class>org.apache.cayenne.conf.WebApplicationContextFilter</filter-class>
    >        </filter>
    >        <filter-mapping>
    >                <filter-name>CayenneFilter</filter-name>
    >                <servlet-name>/*</servlet-name>
    >        </filter-mapping>
    >
    > I then implemented HttpSessionAttributeListener in my class and used the following code within it:
    >
    >        public void attributeAdded(HttpSessionBindingEvent arg0) {
    >                ObjectContext ctx = null;
    >                try{
    >                        ctx = BaseContext.getThreadObjectContext();
    >                }catch(Exception e){}
    >
    >                if(ctx != null){
    >                        BaseContext.bindThreadObjectContext(ctx);
    >                        ctx.setUserProperty("myData", this);
    >                }
    >        }
    >
    > The code gets hit and the property is set, but every subsequent call to BaseContext.getThreadObjectContext().getUserProperty("myData") returns null. If I explicitly set the user property with every request, all works fine. Am I missing something?
    >
    > John Kuhns
    >



    This archive was generated by hypermail 2.0.0 : Tue Jun 15 2010 - 14:42:26 UTC