m suresh
m suresh

Reputation: 659

Can't understand connection pooling error using JPA, Tomcat, Oracle

I have the following code in context.xml for Tomcat:

<Resource name="ds/OracleDS" auth="Container" type="javax.sql.DataSource"
maxActive="1" maxIdle="2" maxWait="2"
username="demo" password="demo"
driverClassName="oracle.jdbc.driver.OracleDriver"
url="jdbc:oracle:thin:@localhost:1521:orcl"/>

I have this code in web.xml:

<resource-ref>
 <description>Oracle Datasource example</description>
 <res-ref-name>ds/OracleDS</res-ref-name>
 <res-type>javax.sql.DataSource</res-type>
 <res-auth>Container</res-auth>
</resource-ref>

I have written code in persistence.xml like:

<persistence-unit name="ReceivablesPU"  transaction-type="RESOURCE_LOCAL">
        <provider>oracle.toplink.essentials.PersistenceProvider</provider>
        <non-jta-data-source>java:ds/OracleDS</non-jta-data-source>

I don't understand java:ds/OracleDS,<Resource name="ds/OracleDS",<res-ref-name>ds/OracleDS</res-ref-name>. The error is:

javax.persistence.PersistenceException: Exception [TOPLINK-7060] (Oracle TopLink Essentials - 2.0 (Build b40-rc (03/21/2007))): oracle.toplink.essentials.exceptions.ValidationException
Exception Description: Cannot acquire data source [java:ds/OracleDS].
Internal Exception: javax.naming.NamingException: This context must be accessed through a java: URL

Upvotes: 6

Views: 1227

Answers (3)

Shivan Dragon
Shivan Dragon

Reputation: 15219

Please see this answer to a similar (but not duplicate question):

Jetty Data Source, Hibernate, datasource not found

Depending on Java EE Web App container, for a data source named "ds/OracleDS" you may need to prefix its JNDI context with "java:comp/env" when addressing it (like , in your persistence.xml file) to make it work.

In your particular case of Tomcat, I'd try the following:

<Resource name="ds/OracleDS" auth="Container" type="javax.sql.DataSource"
maxActive="1" maxIdle="2" maxWait="2"
username="demo" password="demo"
driverClassName="oracle.jdbc.driver.OracleDriver"
url="jdbc:oracle:thin:@localhost:1521:orcl"/>

You don't really need anything in your web.xml. The above configuration in context.xml will make Tomcat expose the data source as a JNDI resource

Finally, in persistence.xml put:

<persistence-unit name="ReceivablesPU"  transaction-type="RESOURCE_LOCAL">
        <provider>oracle.toplink.essentials.PersistenceProvider</provider>
        <non-jta-data-source>java:comp/env/ds/OracleDS</non-jta-data-source>

Upvotes: 0

m suresh
m suresh

Reputation: 659

i changes in contex.xml:

<Resource name="OracleDS" auth="Container" type="javax.sql.DataSource"
    maxActive="1" maxIdle="2" maxWait="2"
    username="demo" password="demo"
    driverClassName="oracle.jdbc.driver.OracleDriver"
    url="jdbc:oracle:thin:@localhost:1521:orcl"/>

i changes in web.xml:

<resource-ref>
     <description>Oracle Datasource example</description>
     <res-ref-name>OracleDS</res-ref-name>
     <res-type>javax.sql.DataSource</res-type>
     <res-auth>Container</res-auth>
    </resource-ref>

i changes in persistence.xml

<persistence-unit name="ReceivablesPU"  transaction-type="RESOURCE_LOCAL">
        <provider>oracle.toplink.essentials.PersistenceProvider</provider>
        <non-jta-data-source>java:comp/env/OracleDS</non-jta-data-source>

then i got the output....

Upvotes: 1

Bob
Bob

Reputation: 5618

In persistence.xml, your third line should look like this:

        <non-jta-data-source>java:comp/env/ds/OracleDS</non-jta-data-source>

Upvotes: 2

Related Questions