cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Kuhns, John" <jku...@AimNTLS.com>
Subject RE: BaseContext in servlet
Date Tue, 15 Jun 2010 14:41:56 GMT
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:mgentry@masslight.net] 
Sent: Tuesday, June 15, 2010 10:31 AM
To: user@cayenne.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 <jkuhns@aimntls.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
>

Mime
View raw message