You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@openjpa.apache.org by Joshua Jackson <jo...@gmail.com> on 2007/06/06 14:03:39 UTC
Injecting EntityManager to a web controller
Dear all,
If I deploy my webapps to a server that has OpenJPA in it (let's say
Geronimo). How do I inject EntityManager to my web controller? Is it
the same way as shown in OpenJPA examples?
Thanks in advance
--
Let's create a highly maintainable and efficient code
YM!: thejavafreak
Blog: http://www.nagasakti.or.id/roller/joshua/
Re: Injecting EntityManager to a web controller
Posted by Craig L Russell <Cr...@Sun.COM>.
On Jun 6, 2007, at 8:28 AM, David Jencks wrote:
>
> On Jun 6, 2007, at 5:03 AM, Joshua Jackson wrote:
>
>> Dear all,
>>
>> If I deploy my webapps to a server that has OpenJPA in it (let's say
>> Geronimo). How do I inject EntityManager to my web controller?
>
> I'm not sure what your web controller might be. You can inject an
> entity manager into a servlet or jsf managed bean using an
> @PersistenceContext annotation
You can only inject an EM into a servlet if the servlet is single-
threaded. You need to inject an EMF.
You can inject an EM into a jsf managed bean if it is defined as
request scope IIUC.
Craig
> ; the related annotations for EMF or getting an EM into jndi also
> work the same as for ejbs. You can't get an EM injected into a non-
> managed object that you create yourself, for such an object you
> would have to look it up in jndi yourself.
>
> thanks
> david jencks
>
>
>> Is it
>> the same way as shown in OpenJPA examples?
>>
>> Thanks in advance
>>
>> --
>> Let's create a highly maintainable and efficient code
>>
>> YM!: thejavafreak
>> Blog: http://www.nagasakti.or.id/roller/joshua/
>
Craig Russell
Architect, Sun Java Enterprise System http://java.sun.com/products/jdo
408 276-5638 mailto:Craig.Russell@sun.com
P.S. A good JDO? O, Gasp!
Re: Injecting EntityManager to a web controller
Posted by David Jencks <da...@yahoo.com>.
On Jun 6, 2007, at 5:03 AM, Joshua Jackson wrote:
> Dear all,
>
> If I deploy my webapps to a server that has OpenJPA in it (let's say
> Geronimo). How do I inject EntityManager to my web controller?
I'm not sure what your web controller might be. You can inject an
entity manager into a servlet or jsf managed bean using an
@PersistenceContext annotation; the related annotations for EMF or
getting an EM into jndi also work the same as for ejbs. You can't
get an EM injected into a non-managed object that you create
yourself, for such an object you would have to look it up in jndi
yourself.
thanks
david jencks
> Is it
> the same way as shown in OpenJPA examples?
>
> Thanks in advance
>
> --
> Let's create a highly maintainable and efficient code
>
> YM!: thejavafreak
> Blog: http://www.nagasakti.or.id/roller/joshua/