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
[Tomcat-users] Tomcat 6.0, JPA and Resource Injection
| Tweet |
|
Search Discussions
Discussion Posts
Follow ups
- Christopher Schultz: Alonso, A. Alonso Domínguez wrote: 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 --------------------------------------------------------------------- To start a new topic, e-mail: users@tomcat.apache.org To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org For additional
- A. Alonso Domínguez: 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 "" element from web.xml, is this correct? Christopher Schultz escribió: 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
- Christopher Schultz: Alonso, A. Alonso Domínguez wrote: I don't really know. I haven't been able to find a DTD or schema for web.xml that has the 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 --------------------------------------------------------------------- To start a new topic, e-mail: users@tomcat.apache.org To unsubscribe, e-mail:
Related Discussions
Discussion Overview
| group | users
|
| categories | tomcat |
| posted | Sep 13, '07 at 9:29a |
| active | Sep 13, '07 at 4:46p |
| posts | 5 |
| users | 3 |
| website | tomcat.apache.org |
| irc | #tomcat |
