Reputation: 71
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:
Modify server.xml as suggested - Tried with both Connecting to Local Db and Database hosted as a part of Web Starter app-
The Server.xml
<!-- Enable features -->
<featureManager>
<feature>webProfile-7.0</feature>
<feature>localConnector-1.0</feature>
</featureManager>
<!-- To access this server from a remote client add a host attribute to the following element, e.g. host="*" -->
<httpEndpoint httpPort="9080" httpsPort="9443" id="defaultHttpEndpoint"/>
<!-- Automatically expand WAR files and EAR files -->
<applicationManager autoExpand="true"/>
<applicationMonitor updateTrigger="mbean"/>
<library id="MySQLLib">
<fileset dir="${server.config.dir}/lib" id="mysql-connector-jar" includes="mysql-connector-java-*.jar"/>
</library>
<webApplication id="JavaDBApp" location="liberty-IRDS.war" name="JavaDBApp"/>
</server>
Also Tried :To connect to DB in Java DB Web starter
<server description="new server">
<!-- Enable features -->
<featureManager>
<feature>webProfile-7.0</feature>
<feature>localConnector-1.0</feature>
</featureManager>
<!-- To access this server from a remote client add a host attribute to the following element, e.g. host="*" -->
<httpEndpoint httpPort="9080" httpsPort="9443" id="defaultHttpEndpoint"/>
<!-- Automatically expand WAR files and EAR files -->
<applicationManager autoExpand="true"/>
<applicationMonitor updateTrigger="mbean"/>
<dataSource id="mydbdatasource" jndiName="jdbc/mydbdatasource">
<jdbcDriver libraryRef="MySQLLib"/>
<properties url="db2://user13711:[email protected]:50000/SQLDB" user="user13711" password="****"/>
</dataSource>
<library id="MySQLLib">
<fileset dir="${server.config.dir}/lib" id="mysql-connector-jar" includes="mysql-connector-java-*.jar"/>
</library>
<webApplication id="JavaDBApp" location="liberty-IRDS.war" name="JavaDBApp"/>
</server>
Upvotes: 3
Views: 361
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.
webProfile-7.0
turns on jdbc-4.1
)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