refering Tomcat JNDI datasource in persistence.xml

Posted by binary_runner on Stack Overflow See other posts from Stack Overflow or by binary_runner
Published on 2010-05-26T08:56:51Z Indexed on 2010/05/26 10:01 UTC
Read the original article Hit count: 499

Filed under:
|
|
|
|

in server.xml I've defined global resource (I'm using Tomcat 6):

<GlobalNamingResources>
   <Resource name="jdbc/myds" auth="Container"
             type="javax.sql.DataSource"
             maxActive="10" maxIdle="3" maxWait="10000"
             username="sa"  password=""
             driverClassName="org.h2.Driver"
             url="jdbc:h2:~/.myds/data/db"
   />
</GlobalNamingResources>

I see in catalina.out that this is bound, so I suppose it's OK.

In my web app I have the link to the datasource, I'm not sure it's OK:

<Context>    
 <ResourceLink global='jdbc/myds' name='jdbc/myds' type="javax.sql.Datasource"/>    
</Context>

and in application there is persistence.xml :

<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_2_0.xsd"
             version="2.0">
  <persistence-unit name="oam" transaction-type="RESOURCE_LOCAL">
    <provider>org.hibernate.ejb.HibernatePersistence</provider>
    <non-jta-data-source>jdbc/myds</non-jta-data-source>
    <!-- class definitions here, nothing else -->

    <properties>
      <property name="hibernate.dialect" value="org.hibernate.dialect.H2Dialect"/>
    </properties>
  </persistence-unit>
</persistence>

It shuld be OK, but most probably this or the ResourceLink definition is wrong because I'm getting:

javax.naming.NameNotFoundException: Name jdbc is not bound in this Context

What's wrong and why this does not work ?

© Stack Overflow or respective owner

Related posts about java

Related posts about hibernate