All I want is to access a H2 mem database in Websphere V8 using JPA 2.0

1.3k views Asked by At

I've been struggling with this for days now and I searched dozens of articles in StackOverflow and other dev sites.

I used the Deployment Manager interface to configure a Websphere Application Server 8.0.0.3 with a H2 JDBC provider and a Data Source for my application using a tutorial I've found here.

JDBC Data Source:

Name: H2 JDBC Provider
Classpath: $(H2_JDBC_DRIVER_PATH)/h2-1.3.161.jar
Implementation class name: org.h2.jdbcx.JdbcDataSource

Data Source:

Provider: H2 JDBC Provider
Name: SGO_datasource
JNDI name: jdbc/sgodb
Use this data source in container managed persistence (CMP): true
Data store helper class name: com.ibm.websphere.rsadapter.ConnectJDBCDataStoreHelper (user-defined)
(default values for all the rest)
Custom properties:
    URL: jdbc:h2:mem:test;DB_CLOSE_DELAY=-1
    user: sa
    password: sa

I tested this datasource using the Test connection button in the DM and it worked fine.

When I try to access this datasource from my app I get this error on first access:

Caused by: <openjpa-2.1.2-SNAPSHOT-r422266:1227818 fatal user error> org.apache.openjpa.persistence.ArgumentException: A JDBC Driver or DataSource class name must be specified in the ConnectionDriverName property.

After reading this issue, I checked the location of my persistence.xml file in the WAR generated and it seems to be in the right location: WEB-INF/classes/META-INF/persistence.xml.

Persistence.xml:

<persistence version="2.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_2_0.xsd">
   <persistence-unit name="sgo">
      <jta-data-source>java:comp/env/jdbc/sgodb</jta-data-source>
   </persistence-unit>
</persistence>

Any ideas? Thanks in advance.

1

There are 1 answers

0
herbae On BEST ANSWER

Found it!

These full JNDI names doesn't seem to work in Websphere. I used a plain "jdbc/sgodb" instead and it could find the context.

<jta-data-source>jdbc/sgodb</jta-data-source>

instead of

<jta-data-source>java:comp/env/jdbc/sgodb</jta-data-source>