FAQ

[Tomcat-users] Tomcat 6.0, JPA and Resource Injection

A. Alonso Domínguez
Sep 13, 2007 at 9:29 am
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
reply

Search Discussions

Discussion Posts

Follow ups

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 1 of 5 | next ›