I'm working on some legacy code that has a bean not bound error. This seems fairly common but so far all of the solutions offered online have not worked (generally ensuring the datasource is defined correctly or class loading issues). The issue is also compounded by the fact that sometimes the bean will bind and sometimes not.
The bean does show as bound in the logs:
2015-12-21 09:44:56,203 DEBUG [org.jboss.ejb3.proxy.impl.jndiregistrar.JndiSessionRegistrarBase] (main) Bound javax.naming.Reference into JNDI at "MyBean/local"
2015-12-21 09:44:56,203 DEBUG [org.jboss.ejb3.proxy.impl.jndiregistrar.JndiSessionRegistrarBase] (main) Bound javax.naming.Reference into JNDI at "MyBean/local-package.MyBeanInterface"
It also shows as bound in the JNDI tree and the name matches the one used in the code.
But then later
org.jboss.soa.esb.ConfigurationException: javax.naming.NameNotFoundException: MyBean not bound
I think I've tracked the cause down to component loading order. On an unsuccessful deployment the DEBUG logs show:
2015-12-21 09:44:54,471 DEBUG [org.jboss.deployers.structure.spi.helpers.AbstractDeploymentContext] (main) Added component jboss.j2ee:jar=myesb.esb,name=mybean,service=EJB3_endpoint to vfszip:/jboss-as/server/default/deploy/myesb.esb/
2015-12-21 09:44:54,471 DEBUG [org.jboss.deployers.structure.spi.helpers.AbstractDeploymentContext] (main) Added component jboss.esb.vfszip:jboss-as/server/default/deploy/myesb.esb/ to vfszip:/jboss-as/server/default/deploy/myesb.esb/
2015-12-21 09:44:54,472 DEBUG [org.jboss.deployers.structure.spi.helpers.AbstractDeploymentContext] (main) Added component persistence.unit:unitName=myesb.esb#my-unit to vfszip:/jboss-as/server/default/deploy/myesb.esb/
On a successful deployment DEBUG logs show:
2015-12-21 11:59:51,331 DEBUG [org.jboss.deployers.structure.spi.helpers.AbstractDeploymentContext] (main) Added component persistence.unit:unitName=myesb.esb#my-unit to vfszip:/jboss-as/server/default/deploy/myesb.esb/
2015-12-21 11:59:51,332 DEBUG [org.jboss.deployers.structure.spi.helpers.AbstractDeploymentContext] (main) Added component jboss.j2ee:jar=myesb.esb,name=mybean,service=EJB3_endpoint to vfszip:/jboss-as/server/default/deploy/myesb.esb/
2015-12-21 11:59:51,333 DEBUG [org.jboss.deployers.structure.spi.helpers.AbstractDeploymentContext] (main) Added component jboss.esb.vfszip:/jboss-as/server/default/deploy/myesb.esb/ to vfszip:/jboss-as/server/default/deploy/myesb.esb/
I have two separate ESBs that share the same datasource and persistence unit, and both use stateless beans.
The persistence.xml is the same for both and in the META-INF directory:
<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
version="1.0">
<persistence-unit name="my-unit">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<jta-data-source>java:jdbc/MyDS</jta-data-source>
<mapping-file>hibernate.cfg.xml</mapping-file>
<properties>
<property name="hibernate.cache.use_second_level_cache" value="true"/>
<property name="hibernate.cache.provider_class" value="org.hibernate.cache.HashtableCacheProvider"/>
<property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect" />
<property name="hibernate.default_schema" value="myvalue" />
</properties>
</persistence-unit>
</persistence>
And the datasource file is:
<local-tx-datasource>
<jndi-name>jdbc/MyDS</jndi-name>
<connection-url>jdbc:postgresql://localhost:5432/mydb</connection-url>
<driver-class>org.postgresql.Driver</driver-class>
<user-name>username</user-name>
<password>password</password>
<min-pool-size>5</min-pool-size>
<max-pool-size>25</max-pool-size>
<metadata>
<type-mapping>PostgreSQL</type-mapping>
</metadata>
</local-tx-datasource>
How can I control the order of loading so that the persistence unit is always loaded first? Or is this not a loading order issue but instead caused by possibly two ESBs sharing the same persistence unit?
Update
I can reproduce the error with the following steps:
- Deploy both ESBs and there are no errors
- Shutdown the server, redeploy the ESB with the stateless bean that always binds ok and then the other ESB throws the error
- Restart the server and all is ok again
Update 2
Logging a list of the root JNDI context shows that on a successful deployment, the persistence unit is available within the JNDI context.
Update 3
I've got a solution that I think is a workaround rather than a fix. I force the ESB that was breaking to be dependent on the one that is working (both share the same persistence unit and datasource) by adding the following to a deployment.xml
file placed in the META-INF folder of the package:
<?xml version="1.0" encoding="UTF-8"?><jbossesb-deployment>
<depends>jboss.esb:deployment=my-working-esb.esb</depends>
</jbossesb-deployment>
So the working ESB is always deployed first meaning the persistence unit is available to the other ESB in the JNDI context. However, this doesn't answer why the persistence unit is loaded first. I thought it might be related to packaging - the broken ESB uses the jboss-packaging-maven-plugin whereas the working one doesn't; but looking at the source code for that project doesn't yield any immediate answers.
What are the possible causes that mean JBOSS/Hibernate loads the persistence unit before the ESB?
NB:
- both ESBs deploy ok independently of one another
- hibernate core 3.3.2.GA
- JBOSS SOA-P 5.3