我们有一个有很多依赖项目的项目。我现在对Websphere资源绑定和资源定义感到困惑。
可以说,我有一个* .jar,它在persistance.xml(jta-data-source)中定义了数据源,在ejb-jar.xml中有相同的数据源(enterprise-beans / session / resource-ref) ,并且还具有此数据源的绑定ibm-web-bnd.xml(resource-ref)。
现在我想在* .war。
中使用这个* .jar让我们假设我已正确配置了我的Websphere Liberty服务器上的所有资源。
在应用程序启动期间,我对此* .jar有以下错误:
Unable to use JDBC Connection to create Statement
java.sql.SQLException: Unsupported use of GenericConnection. A
GenericConnection is provided during application start when creating an
EntityManagerFactory for a persistence unit which has configured one of its
datasource to be in the component naming context; java:comp/env. During
application start, the component naming context will not exist, and the
correct datasource cannot be determined. When the persistence unit is used,
the proper datasource and connection will be obtained and used.
问题:
* .jar中的代码,我无法修改,但必须在我的* .war中使用
EJB-jar.xml中
...
<enterprise-beans>
<session id="MyEntityManagerBean">
<ejb-name>MyEntityManagerBean</ejb-name>
<ejb-class>somepackage.MyEntityManagerBean</ejb-class>
<session-type>Stateless</session-type>
<transaction-type>Container</transaction-type>
<resource-ref id="some_id_goes_here">
<res-ref-name>jdbc/my_ds</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>
...
persistance.xml
<persistence-unit name="MyPersistentUnit" transaction-type="JTA">
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<jta-data-source>java:comp/env/jdbc/my_ds</jta-data-source>
...
</persistence-unit>
IBM-EJB-JAR-bnd.xml
...
<session name="MyEntityManagerBean">
<resource-ref name="jdbc/my_ds" binding-name="jdbc/my_ds"/>
</session>
<session name="MyEntityManagerBean2">
<resource-ref name="jdbc/my_ds" binding-name="jdbc/my_ds"/>
</session>
...
MyEntityManagerBean.java(也是* .jar)
@PersistenceContext(unitName="MyPersistentUnit")
protected EntityManager entityManager;
当我将* .jar作为Maven依赖项添加到我的* .war时,问题就开始了。
提前致谢。