1
votes

I have a Java EE Application consisting many modules. I am trying to be able to make Indirect JNDI lookups.

I followed these Steps:

ejb-jar.xml: In each module. i defined an enterprise bean. All DAOs in the module inherits from this DAO(MyDataAccessObject)


<enterprise-beans>
        <session>
            <ejb-name>DataAccessObject</ejb-name>
            <ejb-class>com.mycompany.dao.MyDataAccessObject</ejb-class>
            <session-type>Stateless</session-type>
            <transaction-type>Container</transaction-type>
            <resource-ref id="MyRef">
                <description />
                <res-ref-name>jdbc/My_db</res-ref-name>
                <res-type>javax.sql.DataSource</res-type>
                <res-auth>Container</res-auth>
                <res-sharing-scope>Shareable</res-sharing-scope>
            </resource-ref>
        </session>
</enterprise-beans>

persistence.xml : I defined in each persistence.xml (in every module)


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

ibm-application-bnd.xml


 <resRefBindings xmi:id="MyRef" jndiName="jdbc/My_db">

    ?????? Should I use resRefBindings. If yes, how? 
</resRefBindings>

What should i add to this document that Websphere knows about java:comp/env/jdbc/My_db?

Is it enough/correct what i have already done?

Currently I get this error if i want to start the application:

The server cannot locate the java:comp/env/jdbc/my_db data source for the My_Modul persistence unit because it has encountered the following exception:
 Name comp/env/jdbc not found in context "java:".

Edit: I found also this error in an incident file:

Caused by: <openjpa-2.1.2-SNAPSHOT-r422266:1384519 fatal user error> org.apache.openjpa.persistence.ArgumentException: A JDBC Driver or DataSource class name must be specified in the ConnectionDriverName property.
    at org.apache.openjpa.jdbc.schema.DataSourceFactory.newDataSource(DataSourceFactory.java:76)
    at org.apache.openjpa.jdbc.conf.JDBCConfigurationImpl.createConnectionFactory(JDBCConfigurationImpl.java:844)
    at org.apache.openjpa.jdbc.conf.JDBCConfigurationImpl.getDBDictionaryInstance(JDBCConfigurationImpl.java:602)
    at org.apache.openjpa.jdbc.meta.MappingRepository.endConfiguration(MappingRepository.java:1510)
1
Did you try just using jdbc/My_db in your jta-data-source? I admit I haven't done exactly this but am thinking that however you map it, the way you reference it will be via the res-ref-name. (We always map our references at deploy time through the WebSphere console rather than by creating the binding files.) - dbreaux
WebSphere does have support for java:comp names in persistence.xml, though I do not believe that is defined by the spec. Please show the full exception (for "Currently i get this error at deployment"), which might have additional hints as to why the lookup failed. - Brett Kail
@bkail I added an error in an incident file. Does it say something to you? - Kayser
@dbreaux can you deliver a sample how it can work - Kayser
@Kayser yes, the error message usually means that DataSource lookup failed; that error should be preceded by CWWJP0013E. - Brett Kail

1 Answers

1
votes

You use XMI bindings (resRefBindings) which are supported in WAS 7.0 but considered obsolete. It is recommended to use XML bindings. In META-INF there should be file named ibm-ejb-jar-bnd.xml with contents like this:

<ejb-jar-bnd xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://websphere.ibm.com/xml/ns/javaee"
    xsi:schemaLocation="http://websphere.ibm.com/xml/ns/javaee http://websphere.ibm.com/xml/ns/javaee/ibm-ejb-jar-bnd_1_0.xsd" version="1.0">
  <session name="DataAccessObject">
    <resource-ref name="**datasource_ref_in_your_EJB**" binding-name="jdbc/My_db"/>
  </session>
</ejb-jar-bnd>

I also assume you already have datasource with JNDI name "jdbc/My_db" configured within WAS.