Tomcat 6, JPA and Data sources

Posted by asrijaal on Stack Overflow See other posts from Stack Overflow or by asrijaal
Published on 2010-03-17T08:17:00Z Indexed on 2010/03/17 8:21 UTC
Read the original article Hit count: 514

Filed under:
|
|

Hi there,

I'm trying to get a data source working in my jsf app. I defined the data source in my web-apps context.xml

webapp/META-INF/context.xml

<?xml version="1.0" encoding="UTF-8"?>
<Context antiJARLocking="true" path="/Sale">
<Resource auth="Container" 
   driverClassName="com.mysql.jdbc.Driver" 
   maxActive="20" 
   maxIdle="10" 
   maxWait="-1" 
   name="Sale" 
   password="admin" 
   type="javax.sql.DataSource" 
   url="jdbc:mysql://localhost/sale" 
   username="admin"/>
</Context>

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<filter>
<display-name>RichFaces Filter</display-name>
<filter-name>richfaces</filter-name>
<filter-class>org.ajax4jsf.Filter</filter-class>
</filter>
<filter-mapping>
<filter-name>richfaces</filter-name>
<servlet-name>Faces Servlet</servlet-name>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
<dispatcher>INCLUDE</dispatcher>
</filter-mapping>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/faces/*</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>
    30
</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>faces/welcomeJSF.jsp</welcome-file>
</welcome-file-list>
<context-param>
<param-name>org.richfaces.SKIN</param-name>
<param-value>ruby</param-value>
</context-param>
</web-app>

and my persistence.xml

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.0" 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">
<persistence-unit name="SalePU" transaction-type="RESOURCE_LOCAL">
<provider>oracle.toplink.essentials.PersistenceProvider</provider>
<non-jta-data-source>Sale</non-jta-data-source>
<class>org.comp.sale.AnfrageAnhang</class>
<class>org.comp.sale.Beschaffung</class>
<class>org.comp.sale.Konto</class>
<class>org.comp.sale.Anfrage</class>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
</persistence-unit>
</persistence>

But no data source seems to be created by Tomcat, I only get this exception

Exception [TOPLINK-7060] (Oracle TopLink Essentials - 2.0.1 (Build b09d-fcs (12/06/2007))): oracle.toplink.essentials.exceptions.ValidationException
Exception Description: Cannot acquire data source [Sale].
Internal Exception: javax.naming.NameNotFoundException: Name Sale is not bound in this Context

The needed jars for the MySQL driver are included into the WEB-INF/lib dir.

What I'm doing wrong?

© Stack Overflow or respective owner

Related posts about tomcat

Related posts about java