cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Michael Gentry <mgen...@masslight.net>
Subject Re: ObjectContext per thread or per app?
Date Wed, 16 Feb 2011 14:17:56 GMT
Hi Christian,

You'll typically have at least one context-per-user.  (Not always, but
typically.)  The patterns we use here are to have a thread-based
context-per-user and also separate (peer or child) contexts on our
edit pages.  This lets us isolate the edit changes in a different
context (and wire the UI directly to the underlying Cayenne object)
and we are able to throw the context away without polluting the main
thread-based context when needed (such as when there are validation
errors and the user cancels instead of fixing them).  This approach
keeps unexpected modified objects from floating around in our
thread-based context that might later get committed when we didn't
want them.

mrg


On Wed, Feb 16, 2011 at 5:18 AM, Christian Grobmeier
<grobmeier@gmail.com> wrote:
> Thanks Andrey,
> this helped.
> Christian
>
> On Wed, Feb 16, 2011 at 10:56 AM, Andrey Razumovsky
> <razumovsky.andrey@gmail.com> wrote:
>> Hi Christian,
>>
>> In case of Web application it is incorrect to have one ObjectContext,
>> because you can't really know which session added certain changes, so
>> you'll be facing tons of multithreading issues, e.g. one session will
>> commit other session's partial changes. Common way is to have one
>> context per session, and for easy access to it having it bound to your
>> servlet's thread. See
>> http://cayenne.apache.org/doc30/web-applications.html
>>
>> Hope that helps,
>> Andrey
>>
>> 2011/2/16 Christian Grobmeier <grobmeier@gmail.com>:
>>> Hello,
>>>
>>> sorry, a dumb question:
>>>
>>> do I need a ObjectContext per thread or per app?
>>>
>>> In fact I wrote a spring bean (its a singleton) which creates one
>>> single ObjectContext for all my app. In other terms, multiple threads
>>> will use it to insert, read, commit etc.
>>> Since ObjectContext offers the commit method, I am now doubting if
>>> this was correct. I feel it might be good to have an ObjectContext for
>>> each thread/user. Or does the ObjectContext know what happened as one
>>> transaction?
>>>
>>> Can you advise?
>>>
>>> Thanks
>>> Christian
>>>
>>> --
>>> http://www.grobmeier.de
>>>
>>
>>
>>
>> --
>> Andrey
>>
>
>
>
> --
> http://www.grobmeier.de
>

Mime
View raw message