We have a project that have quite a lot of dependencies. I am confused in Websphere resource binding and resource definition at all now.
- ejb-jar.xml describes resources.
- persistance.xml describes database resources.
- We can have web.xml, where we describes resources also.
- We can have ibm-web-bnd.xml, where we can have binding for resources.
Lets say, I have a *.jar that has definition of data source in persistance.xml (jta-data-source), same data source in ejb-jar.xml (enterprise-beans/session/resource-ref), and also has binding for this data source ibm-web-bnd.xml (resource-ref).
Now I want to use this *.jar in my *.war.
Lets assume that I have configured all resources on my Websphere Liberty server correctly.
During application start up, I've got following error for this *.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.
Questions:
- Why my *.jar do not see Data Source, that I have defined on my Websphere Libery (in server.xml)? Do I miss some binding in my *.war?
- Why do we describe resources in web.xml? I thought that this is definition of web application, like a servlet mapping, filters, etc.
- Why same data source is described in both persistance.xml and ejb-jar.xml (is it not enough with persistance.xml?)?
- Does resource binding delay somehow dependency injection?
Code in *.jar that I can't modify, but have to use in my *.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 (also same *.jar)
@PersistenceContext(unitName="MyPersistentUnit")
protected EntityManager entityManager;
And problem starts, when I add this *.jar as Maven dependency to my *.war.
Thanks in advance.