You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Musachy Barroso <mu...@gmail.com> on 2009/03/18 18:39:14 UTC

Re: [S2] Struts 2 + Spring 2 + JPA example uses @PersistenceContext - is this a "bad thing"??

I had no idea it was not thread safe, in that case it is probably a
good idea to get factory and create an entity manager every time.

musachy

On Wed, Mar 18, 2009 at 1:30 PM, Burton Rhodes <bu...@gmail.com> wrote:
> I set up the example for "Struts 2 + Spring 2 + JPA + AJAX" using the
> OpenEntityManagerInViewFilter from the Struts website and all works
> well. (http://struts.apache.org/2.0.14/docs/struts-2-spring-2-jpa-ajax.html).
>  It appears this example uses the @PersistenceContext annotation to
> inject the EntityManger into each Service/Dao class...
>
> Then I read this blog about how you SHOULD NOT use @PersistenceContext
> annotation in a webapp becasue of thread safety unless you implement a
> SingleThreadModel.
>
> http://weblogs.java.net/blog/ss141213/archive/2005/12/dont_use_persis_1.html
>
> Now I am confused...  Should I instead use @PersistenceUnit to inject
> the EntityManagerFactor into each Dao object?  And if so, won't this
> affect the OpenEntityManagerInViewFilter and cause Lazy exceptions?
> Can someone shead some light on this for me or am I not understanding
> this correctly?
>
> Apologies in advance if this is a bit off Struts topic...
>
> Thanks,
> Burton
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>



-- 
"Hey you! Would you help me to carry the stone?" Pink Floyd

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: [S2] Struts 2 + Spring 2 + JPA example uses @PersistenceContext - is this a "bad thing"??

Posted by Burton Rhodes <bu...@gmail.com>.
Many thanks for your efforts. I do have everyting in appcontext file.
I am using @Transactional and I am not using jpasupport. Let me know
what you find out and if jpasupport is necessary.

On 3/18/09, Wes Wannemacher <we...@wantii.com> wrote:
> I haven't read that blog post, but I do know that Spring treats
> @PersistenceContext differently than an EJB container. If you've
> configured everything within applicationContext.xml, rather than in
> the AppServer, and if you are extending JpaDaoSupport then I would
> think it should work properly. I will check it out tonight if I get a
> chance.
>
> -Wes
>
> On Wed, Mar 18, 2009 at 1:39 PM, Musachy Barroso <mu...@gmail.com> wrote:
>> I had no idea it was not thread safe, in that case it is probably a
>> good idea to get factory and create an entity manager every time.
>>
>> musachy
>>
>> On Wed, Mar 18, 2009 at 1:30 PM, Burton Rhodes <bu...@gmail.com>
>> wrote:
>>> I set up the example for "Struts 2 + Spring 2 + JPA + AJAX" using the
>>> OpenEntityManagerInViewFilter from the Struts website and all works
>>> well.
>>> (http://struts.apache.org/2.0.14/docs/struts-2-spring-2-jpa-ajax.html).
>>>  It appears this example uses the @PersistenceContext annotation to
>>> inject the EntityManger into each Service/Dao class...
>>>
>>> Then I read this blog about how you SHOULD NOT use @PersistenceContext
>>> annotation in a webapp becasue of thread safety unless you implement a
>>> SingleThreadModel.
>>>
>>> http://weblogs.java.net/blog/ss141213/archive/2005/12/dont_use_persis_1.html
>>>
>>> Now I am confused...  Should I instead use @PersistenceUnit to inject
>>> the EntityManagerFactor into each Dao object?  And if so, won't this
>>> affect the OpenEntityManagerInViewFilter and cause Lazy exceptions?
>>> Can someone shead some light on this for me or am I not understanding
>>> this correctly?
>>>
>>> Apologies in advance if this is a bit off Struts topic...
>>>
>>> Thanks,
>>> Burton
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>>> For additional commands, e-mail: user-help@struts.apache.org
>>>
>>>
>>
>>
>>
>> --
>> "Hey you! Would you help me to carry the stone?" Pink Floyd
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>>
>
>
>
> --
> Wes Wannemacher
> Author - Struts 2 In Practice
> Includes coverage of Struts 2.1, Spring, JPA, JQuery, Sitemesh and more
> http://www.manning.com/wannemacher
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

-- 
Sent from my mobile device

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: [S2] Struts 2 + Spring 2 + JPA example uses @PersistenceContext - is this a "bad thing"??

Posted by Wes Wannemacher <we...@wantii.com>.
I haven't read that blog post, but I do know that Spring treats
@PersistenceContext differently than an EJB container. If you've
configured everything within applicationContext.xml, rather than in
the AppServer, and if you are extending JpaDaoSupport then I would
think it should work properly. I will check it out tonight if I get a
chance.

-Wes

On Wed, Mar 18, 2009 at 1:39 PM, Musachy Barroso <mu...@gmail.com> wrote:
> I had no idea it was not thread safe, in that case it is probably a
> good idea to get factory and create an entity manager every time.
>
> musachy
>
> On Wed, Mar 18, 2009 at 1:30 PM, Burton Rhodes <bu...@gmail.com> wrote:
>> I set up the example for "Struts 2 + Spring 2 + JPA + AJAX" using the
>> OpenEntityManagerInViewFilter from the Struts website and all works
>> well. (http://struts.apache.org/2.0.14/docs/struts-2-spring-2-jpa-ajax.html).
>>  It appears this example uses the @PersistenceContext annotation to
>> inject the EntityManger into each Service/Dao class...
>>
>> Then I read this blog about how you SHOULD NOT use @PersistenceContext
>> annotation in a webapp becasue of thread safety unless you implement a
>> SingleThreadModel.
>>
>> http://weblogs.java.net/blog/ss141213/archive/2005/12/dont_use_persis_1.html
>>
>> Now I am confused...  Should I instead use @PersistenceUnit to inject
>> the EntityManagerFactor into each Dao object?  And if so, won't this
>> affect the OpenEntityManagerInViewFilter and cause Lazy exceptions?
>> Can someone shead some light on this for me or am I not understanding
>> this correctly?
>>
>> Apologies in advance if this is a bit off Struts topic...
>>
>> Thanks,
>> Burton
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>>
>
>
>
> --
> "Hey you! Would you help me to carry the stone?" Pink Floyd
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>



-- 
Wes Wannemacher
Author - Struts 2 In Practice
Includes coverage of Struts 2.1, Spring, JPA, JQuery, Sitemesh and more
http://www.manning.com/wannemacher

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: [S2] Struts 2 + Spring 2 + JPA example uses @PersistenceContext - is this a "bad thing"??

Posted by Musachy Barroso <mu...@gmail.com>.
I have no idea :)

musachy

On Wed, Mar 18, 2009 at 1:52 PM, Burton Rhodes <bu...@gmail.com> wrote:
> Any thoughts on how this would affect the
> OpenEntityManagerInViewFilter?  I assume if you create a new EM for
> each service/dao operation, the objects would become detached after
> each method thus giving you a lazy exception for anything in the view
> - rendering the OpenEntityManagerInViewFilter useless.  Am I
> understanding this correctly?
>
> On Wed, Mar 18, 2009 at 12:39 PM, Musachy Barroso <mu...@gmail.com> wrote:
>> I had no idea it was not thread safe, in that case it is probably a
>> good idea to get factory and create an entity manager every time.
>>
>> musachy
>>
>> On Wed, Mar 18, 2009 at 1:30 PM, Burton Rhodes <bu...@gmail.com> wrote:
>>> I set up the example for "Struts 2 + Spring 2 + JPA + AJAX" using the
>>> OpenEntityManagerInViewFilter from the Struts website and all works
>>> well. (http://struts.apache.org/2.0.14/docs/struts-2-spring-2-jpa-ajax.html).
>>>  It appears this example uses the @PersistenceContext annotation to
>>> inject the EntityManger into each Service/Dao class...
>>>
>>> Then I read this blog about how you SHOULD NOT use @PersistenceContext
>>> annotation in a webapp becasue of thread safety unless you implement a
>>> SingleThreadModel.
>>>
>>> http://weblogs.java.net/blog/ss141213/archive/2005/12/dont_use_persis_1.html
>>>
>>> Now I am confused...  Should I instead use @PersistenceUnit to inject
>>> the EntityManagerFactor into each Dao object?  And if so, won't this
>>> affect the OpenEntityManagerInViewFilter and cause Lazy exceptions?
>>> Can someone shead some light on this for me or am I not understanding
>>> this correctly?
>>>
>>> Apologies in advance if this is a bit off Struts topic...
>>>
>>> Thanks,
>>> Burton
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>>> For additional commands, e-mail: user-help@struts.apache.org
>>>
>>>
>>
>>
>>
>> --
>> "Hey you! Would you help me to carry the stone?" Pink Floyd
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>



-- 
"Hey you! Would you help me to carry the stone?" Pink Floyd

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: [S2] Struts 2 + Spring 2 + JPA example uses @PersistenceContext - is this a "bad thing"??

Posted by Burton Rhodes <bu...@gmail.com>.
Any thoughts on how this would affect the
OpenEntityManagerInViewFilter?  I assume if you create a new EM for
each service/dao operation, the objects would become detached after
each method thus giving you a lazy exception for anything in the view
- rendering the OpenEntityManagerInViewFilter useless.  Am I
understanding this correctly?

On Wed, Mar 18, 2009 at 12:39 PM, Musachy Barroso <mu...@gmail.com> wrote:
> I had no idea it was not thread safe, in that case it is probably a
> good idea to get factory and create an entity manager every time.
>
> musachy
>
> On Wed, Mar 18, 2009 at 1:30 PM, Burton Rhodes <bu...@gmail.com> wrote:
>> I set up the example for "Struts 2 + Spring 2 + JPA + AJAX" using the
>> OpenEntityManagerInViewFilter from the Struts website and all works
>> well. (http://struts.apache.org/2.0.14/docs/struts-2-spring-2-jpa-ajax.html).
>>  It appears this example uses the @PersistenceContext annotation to
>> inject the EntityManger into each Service/Dao class...
>>
>> Then I read this blog about how you SHOULD NOT use @PersistenceContext
>> annotation in a webapp becasue of thread safety unless you implement a
>> SingleThreadModel.
>>
>> http://weblogs.java.net/blog/ss141213/archive/2005/12/dont_use_persis_1.html
>>
>> Now I am confused...  Should I instead use @PersistenceUnit to inject
>> the EntityManagerFactor into each Dao object?  And if so, won't this
>> affect the OpenEntityManagerInViewFilter and cause Lazy exceptions?
>> Can someone shead some light on this for me or am I not understanding
>> this correctly?
>>
>> Apologies in advance if this is a bit off Struts topic...
>>
>> Thanks,
>> Burton
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>>
>
>
>
> --
> "Hey you! Would you help me to carry the stone?" Pink Floyd
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org