Hi Tony,

In our case, we were getting extra Cayenne stacks created at runtime.  We
have a bunch of queries that are done at start up (Spring is involved here,
which *might* be part of the problem, but we didn't determine the actual
cause), plus custom types that need to be registered.  For some reason,
registering the custom types at start up didn't seem to apply to the filter
and we ended up with two Cayenne stacks created -- one with the custom
types and one without.  This caused problems.

Also, some parts of the application don't need to have a session (such as
logout), but the filter kept creating them.  Sure, we could've made changes
to the URLs used by the filter/application, but ...

I don't like having a global context in which I commit changes because if
the commit fails (say, a column is missing), it corrupts the entire context
for that session.  You can never commit changes elsewhere in the
application during that session because your old "corrupted" data is still
hanging around because it never got committed, but will try to go along for
the ride during your next commitChanges().

So, my preferred approach is to use separate contexts to isolate
edits/transactions and not have a global filter-based one.  This means each
user session (or even a single web request) can have many separate
contexts, but they are cheap to create and seem to work better (at least
for my scenarios).

mrg


On Thu, Feb 28, 2013 at 11:51 AM, Tony Giaccone <[email protected]> wrote:

> Michael,
>
> I'm just curious, what issues does the filter cause??
>
> Tony
>
> On Feb 28, 2013, at 11:08 AM, Michael Gentry <[email protected]>
> wrote:
>
> > Hi John,
> >
> > We try not to use the CayenneFilter (just removed it from an application
> > because it caused more issues than it solved).  I thought there might be
> a
> > place in 3.1 to stuff the ServerRuntime you initialized on application
> > startup and I was just missing it, but perhaps I just need to save it off
> > in a static somewhere.
> >
> > Thanks,
> >
> > mrg
> >
> >
> > On Thu, Feb 28, 2013 at 10:15 AM, John Huss <[email protected]> wrote:
> >
> >> If it's a servlet app, then the runtime is created in CayenneFilter and
> >> bound to the thread for each request and you access it via
> >>
> >> WebUtil.getCayenneRuntime(servletContext);
> >>
> >>
> >> Or you can get a context from the injector if you have bound that to a
> >> thread:
> >>
> >> ObjectContext context =
> >>
> CayenneRuntime.getThreadInjector().getInstance(ObjectContextFactory.class
> >> ).createContext();
> >>
> >>
> >> If not a servlet app, then yeah, I'd just store it in a static variable
> or
> >> application instance.
> >>
> >>
> >>
> >> On Thu, Feb 28, 2013 at 8:43 AM, Michael Gentry <[email protected]
> >>> wrote:
> >>
> >>> Is there an existing place (class) in 3.1 to stuff a ServerRuntime
> >> instance
> >>> for global use or is it expected that you'll create a separate class to
> >>> hold a static instance variable of ServerRuntime?
> >>>
> >>> Thanks,
> >>>
> >>> mrg
> >>
>

Reply via email to