You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by "A. Alonso Domínguez" <al...@social-labs.com> on 2007/09/13 11:29:03 UTC
Tomcat 6.0, JPA and Resource Injection
Hi there,
I'm trying to set up a web application which uses Java Persistence with
Tomcat 6.0. I had googled and searched a lot of mailing lists but I
didn't found a response for my doubts.
My application uses JSF 1.2 from Sun's RI, some of the managed-beans
defined at that application have a reference to a EntityManager using
the PersistenceContext annotation. This application has been tested
using Glassfish and it works perfectly.
Testing the same application (with all necessary jar files) with Tomcat
throws an exception: javax.naming.NameNotFoundException: The name
java:comp is not associated to this context. This is how my config files
look like:
context.xml:
<Context path="/benedetti-gestion" reloadable="true">
<Resource name="jdbc/benedetti" auth="Container"
type="javax.sql.DataSource"
maxActive="100" maxIdle="30" maxWait="10000"
username="benedetti" password="nsh67eTds"
driverClassName="org.postgresql.Driver"
url="jdbc:postgresql://193.168.3.2:5432/benedetti"
/>
</Context>
persistence.xml:
<?xml version="1.0" encoding="ISO-8859-1"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
version="1.0">
<persistence-unit name="benedetti" transaction-type="RESOURCE_LOCAL">
<provider>
oracle.toplink.essentials.PersistenceProvider
</provider>
<non-jta-data-source>jdbc/benedetti</non-jta-data-source>
<class>benedetti.gestion.entity.Cliente</class>
<class>benedetti.gestion.entity.Expediente</class>
<class>benedetti.gestion.entity.Factura</class>
<class>benedetti.gestion.entity.LineaFactura</class>
</persistence-unit>
</persistence>
web.xml:
<resource-ref>
<res-ref-name>jdbc/benedetti</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
<persistence-context-ref>
<persistence-context-ref-name>jpa/benedetti</persistence-context-ref-name>
<persistence-unit-name>benedetti</persistence-unit-name>
</persistence-context-ref>
I'm configuring the injection of the entity manager as following:
@PersistenceContext(unitName = "benedetti",
name = "java:comp/jpa/benedetti")
private EntityManager em;
About JNDI names, I tried names
Almost all I found in the web about this issue is about Tomcat 5.5.
There is said in many places that Tomcat 5.5 should be treated as a JSE
environment so no dependency injection of "EntityManager" nor
"EntityManagerFactory" is possible. But, what about Tomcat 6 ?
I did take a look to the DefaultAnnotationProcessor class at
"org.apache.catalina.util" and seems to me that class performs
dependency injection based on the kind of annotation found.
My question is: Can I use entity manager injection with Tomcat 6 or do I
need to perform a bootstrap using the Persistence class like in Tomcat 5.5 ?
Regards,
Alonso
---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
RE: Tomcat 6.0, JPA and Resource Injection
Posted by "Caldarale, Charles R" <Ch...@unisys.com>.
> From: "A. Alonso Domínguez" [mailto:alonso.dominguez@social-labs.com]
> Subject: Re: Tomcat 6.0, JPA and Resource Injection
>
> It seems that Tomcat 6 ignores the "<persistence-context-ref>"
> element from web.xml, is this correct?
I can't find any documentation for such an element in either the 2.4 or the 2.5 servlet specs, which is what Tomcat implements. If you're looking for EJB 3.0 extensions beyond that, I suspect you'll have to move up to an full EE container, such as JBoss.
- Chuck
THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY MATERIAL and is thus for use only by the intended recipient. If you received this in error, please contact the sender and delete the e-mail and its attachments from all computers.
---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: Tomcat 6.0, JPA and Resource Injection
Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Alonso,
A. Alonso Domínguez wrote:
> I have tried "java:comp/env/...", "java:/comp/env/...", "java:jpa/..."
> and "jpa/..." as values for the "name" attribute of PersistenceContext
> annotation. None of that paths worked for me. It seems that Tomcat 6
> ignores the "<persistence-context-ref>" element from web.xml, is this
> correct?
I don't really know. I haven't been able to find a DTD or schema for
web.xml that has the <persistence-context-ref> element listed, so I
wouldn't be surprised if it's not supported.
FWIW I have no experience with this particular technology, so I'm just
stabbing in the dark at JNDI issues you might have.
Good luck,
- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iD8DBQFG6WhD9CaO5/Lv0PARAnYFAJ4z3OxbE3NxzqjRhCxIBCYczTxRAwCgl6FF
fVaq4XmJMIXrEW9U0/o7NdI=
=OPWm
-----END PGP SIGNATURE-----
---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: Tomcat 6.0, JPA and Resource Injection
Posted by "A. Alonso Domínguez" <al...@social-labs.com>.
Hi Christopher,
I have tried "java:comp/env/...", "java:/comp/env/...", "java:jpa/..."
and "jpa/..." as values for the "name" attribute of PersistenceContext
annotation. None of that paths worked for me. It seems that Tomcat 6
ignores the "<persistence-context-ref>" element from web.xml, is this
correct?
Christopher Schultz escribió:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Alonso,
>
> A. Alonso Domínguez wrote:
>
>> javax.naming.NameNotFoundException: The name
>> java:comp is not associated to this context.
>>
>
> [snip]
>
>
>> @PersistenceContext(unitName = "benedetti",
>> name = "java:comp/jpa/benedetti")
>> private EntityManager em;
>>
>
> Have you tried "java:/comp/..."?
>
>
>> <persistence-context-ref>
>> <persistence-context-ref-name>jpa/benedetti</persistence-context-ref-name>
>> <persistence-unit-name>benedetti</persistence-unit-name>
>> </persistence-context-ref>
>>
>
> Check out http://blogs.sun.com/pblaha/entry/how_to_use_entitymanager_api
>
I've had take a look to that blog but the example posted there talks
about GlassFish. My app has been tested in GlassFish and there it works,
what I want to try is the same app deployed on a standalone Tomcat.
> They are putting their JNDI resource in a different place in the tree
> (in java:/comp/env/...). You may not be using the right path based on
> where Tomcat puts these resources.
>
> - -chris
>
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.7 (MingW32)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
>
> iD8DBQFG6Uhl9CaO5/Lv0PARAhIdAJ94Mfa3/RhgCHpewfn7Vd+oL0+BewCePWRH
> JbuDjWxwho0U8n5Ft8/+s/k=
> =CJAX
> -----END PGP SIGNATURE-----
>
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>
---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: Tomcat 6.0, JPA and Resource Injection
Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Alonso,
A. Alonso Domínguez wrote:
> javax.naming.NameNotFoundException: The name
> java:comp is not associated to this context.
[snip]
> @PersistenceContext(unitName = "benedetti",
> name = "java:comp/jpa/benedetti")
> private EntityManager em;
Have you tried "java:/comp/..."?
> <persistence-context-ref>
> <persistence-context-ref-name>jpa/benedetti</persistence-context-ref-name>
> <persistence-unit-name>benedetti</persistence-unit-name>
> </persistence-context-ref>
Check out http://blogs.sun.com/pblaha/entry/how_to_use_entitymanager_api
They are putting their JNDI resource in a different place in the tree
(in java:/comp/env/...). You may not be using the right path based on
where Tomcat puts these resources.
- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iD8DBQFG6Uhl9CaO5/Lv0PARAhIdAJ94Mfa3/RhgCHpewfn7Vd+oL0+BewCePWRH
JbuDjWxwho0U8n5Ft8/+s/k=
=CJAX
-----END PGP SIGNATURE-----
---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org