1

我有一个包含许多模块的 Java EE 应用程序。我试图能够进行间接 JNDI 查找。

我按照以下步骤操作:

ejb-jar.xml:在每个模块中。我定义了一个企业 bean。模块中的所有 DAO 都继承自这个 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:我在每个 persistence.xml 中定义(在每个模块中)


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

ibm-应用程序-bnd.xml


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

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

我应该在 Websphere 知道的有关 java:comp/env/jdbc/My_db 的文档中添加什么?

我已经做的足够/正确吗?

目前,如果我想启动应用程序,我会收到此错误:

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:".

编辑:我在事件文件中也发现了这个错误:

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)
4

1 回答 1

1

您使用在 WAS 7.0 中受支持但被认为已过时的 XMI 绑定 (resRefBindings)。建议使用 XML 绑定。META-INF里面应该有这样的内容命名的文件ibm-ejb-jar-bnd.xml

<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>

我还假设您已经在 WAS 中配置了 JNDI 名称为“jdbc/My_db”的数据源。

于 2013-08-02T13:58:44.140 回答