habs
habs

Reputation: 71

Java DB Web starter In Bluemix

I am trying to run a [Java DB Web Starter][1] created in [IBM Bluemix][2] in my local [Websphere Liberty][3] server, but it keeps giving the below error

[ERROR ] CWWJP0029E: The server cannot find the openjpa-todo persistence unit in the liberty-IRDS.war module and the JavaDBApp application. [ERROR ] CWNEN0035E: The java:comp/env/openjpa-todo/entitymanager reference of type javax.persistence.EntityManager for the null component in the liberty-IRDS.war module of the JavaDBApp application cannot be resolved. [err] javax.naming.NamingException: CWNEN1001E: The object referenced by the java:comp/env/openjpa-todo/entitymanager JNDI name could not be instantiated. If the reference name maps to a JNDI name in the deployment descriptor bindings for the application performing the JNDI lookup, make sure that the JNDI name mapping in the deployment descriptor binding is correct. If the JNDI name mapping is correct, make sure the target resource can be resolved with the specified name relative to the default initial context. [Root exception is com.ibm.wsspi.injectionengine.InjectionException: The java:comp/env/openjpa-todo/entitymanager reference of type javax.persistence.EntityManager for the null component in the liberty-IRDS.war module of the JavaDBApp application cannot be resolved.] [err] at com.ibm.ws.injectionengine.osgi.internal.naming.InjectionJavaColonHelper.newCannotInstantiateObjectException(InjectionJavaColonHelper.java:183) [err] at [internal classes] [err] at javax.naming.InitialContext.lookup(Unknown Source) [err] at example.jpa.TODOListResource.getEm(TODOListResource.java:184) [err] at example.jpa.TODOListResource.(TODOListResource.java:35)

Steps done:

Upvotes: 3

Views: 361

Answers (1)

Andy Guibert
Andy Guibert

Reputation: 42926

If you are starting with the boilerplate app, the application is configured properly out of the box on bluemix. It accomplishes this by turning on the cloudAutoWiring-1.0 feature in the server.xm. This will auto-wire jdbc/mydbdatasource to the resource-ref in the application's web.xml.

To use the boilerplate locally:

You need to take a few steps to wire the app to the server, since bluemix can't do that for you in a local environment.

  1. Ensure a jdbc feature is enabled in the server.xml (which you have because webProfile-7.0 turns on jdbc-4.1)
  2. Configure a datasource in your server.xml with the jndi name `"jdbc/mydbdatasource" in the server.xml

Datasource config in the server.xml looks like this:

<dataSource id='mydbdatasource' jndiName='jdbc/mydbdatasource' jdbcDriverRef='myJDBCDriver'> 
    <properties ... />  <!-- depends on what DB you are using -->
</dataSource>

<jdbcDriver id="myJDBCDriver">
    <library>
        <fileset dir="C:/path/to/your/jdbc/driver.jar"/>
    </library>
</jdbcDriver>

As noted in the code sample, the <properties> you use depend on the JDBC driver you are using.
For a listing of what properties to use for all of the main JDBC drivers, look at IBM's DataSource configuration doc.

Upvotes: 1

Related Questions