Tomcat Injection

View: New views
4 Messages — Rating Filter:   Alert me  

Tomcat Injection

by ericp56 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Hello,

After reading some documentation, I though I had my injection code worked
out, but apparently not.

I am using Tomcat with OpenJPA.

In my class, I have:
        @PersistenceUnit(unitName = "CallScheduler")
        private @Resource(name="bean/OpenJPAEMF")OpenJPAEntityManagerFactory emf;
In my META-INF/context.xml, I have:
        <Resource name="bean/OpenJPAEMF" auth="Container"
        factory="org.apache.openjpa.persistence.OpenJPAEntityManagerFactory"
        type="org.apache.openjpa.persistence.OpenJPAEntityManagerFactory.class" />

While executing a method in my class,  emf is still null.

How should I instantiate emf?  I am under the impression that
OpenJPAPersistence.createEntityManagerFactory is for unmanaged code...

Eric
--
View this message in context: http://n2.nabble.com/Tomcat-Injection-tp395699p395699.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.


Re: Tomcat Injection

by ericp56 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


I tried:
        emf = OpenJPAPersistence.getEntityManagerFactory();

but it doesn't find persistence.xml, and raises:
        <openjpa-1.1.0-r422266:657916 fatal user error>
        org.apache.openjpa.persistence.ArgumentException: A JDBC Driver or
DataSource class name
        must be specified in the ConnectionDriverName property.

Are there any samples out there?  The ones included with OpenJPA don't
include any managed resources.


--
View this message in context: http://n2.nabble.com/Tomcat-Injection-tp395699p395729.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.


Parent Message unknown Re: Tomcat Injection

by Hiran Chaudhuri :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Try this:
http://java.sun.com/javaee/5/docs/api/javax/persistence/Persistence.html

For me it worked as soon as OpenJPA was able to find persistence.xml via the classpath.
Alternatively you can provide the whole configuration via the map.

Hiran Chaudhuri

> -----Ursprüngliche Nachricht-----
> Von: "ericp56" <eric.phetteplace@...>
> Gesendet: 08.07.08 22:40:06
> An: users@...
> Betreff: Re: Tomcat Injection


>
> I tried:
> emf = OpenJPAPersistence.getEntityManagerFactory();
>
> but it doesn't find persistence.xml, and raises:
> <openjpa-1.1.0-r422266:657916 fatal user error>
> org.apache.openjpa.persistence.ArgumentException: A JDBC Driver or
> DataSource class name
> must be specified in the ConnectionDriverName property.
>
> Are there any samples out there?  The ones included with OpenJPA don't
> include any managed resources.
>
>
> --
> View this message in context: http://n2.nabble.com/Tomcat-Injection-tp395699p395729.html
> Sent from the OpenJPA Users mailing list archive at Nabble.com.
>
>


____________________________________________________________________
Ihre Messenger, Communities und E-Mails jetzt in einem Programm!
WEB.DE MultiMessenger http://www.produkte.web.de/messenger/?did=3071


Parent Message unknown Re: Tomcat Injection

by Hiran Chaudhuri :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

... on second thought:
Does Tomcat do dependency injection at all? In my eyes it is a servlet container, not an application server. You might want to change to Glassfish, Geronimo or JBoss.

But maybe such behaviour has been introduced to Tomcat and noone ever informed me about it... ;-)

Hiran Chaudhuri


> -----Ursprüngliche Nachricht-----
> Von: "ericp56" <eric.phetteplace@...>
> Gesendet: 08.07.08 22:03:01
> An: users@...
> Betreff: Tomcat Injection


>
> Hello,
>
> After reading some documentation, I though I had my injection code worked
> out, but apparently not.
>
> I am using Tomcat with OpenJPA.
>
> In my class, I have:
> @PersistenceUnit(unitName = "CallScheduler")
> private @Resource(name="bean/OpenJPAEMF")OpenJPAEntityManagerFactory emf;
> In my META-INF/context.xml, I have:
> <Resource name="bean/OpenJPAEMF" auth="Container"
> factory="org.apache.openjpa.persistence.OpenJPAEntityManagerFactory"
> type="org.apache.openjpa.persistence.OpenJPAEntityManagerFactory.class" />
>
> While executing a method in my class,  emf is still null.
>
> How should I instantiate emf?  I am under the impression that
> OpenJPAPersistence.createEntityManagerFactory is for unmanaged code...
>
> Eric
> --
> View this message in context: http://n2.nabble.com/Tomcat-Injection-tp395699p395699.html
> Sent from the OpenJPA Users mailing list archive at Nabble.com.
>
>


_______________________________________________________________________
EINE FÜR ALLE: die kostenlose WEB.DE-Plattform für Freunde und Deine
Homepage mit eigenem Namen. Jetzt starten! http://unddu.de/?kid=kid@mf2

LightInTheBox - Buy quality products at wholesale price