3 Replies Latest reply on Feb 16, 2010 2:57 PM by jaikiran pai

    Nested DataSource fails to deploy before ejbs

    henk de boer Master

      Hi,

       

      I have an EAR application running on JBoss AS 5.1. My EJB module defines a persistence.xml, referencing a data source that is defined using a -ds.xml in the root of my ear. This is all pretty basic and works perfectly most of the time. With the emphasis on most.

       

      Occasionally the deployment fails and JBoss AS states it can't find the data source. I found the following JIRA issue regarding this: https://jira.jboss.org/jira/browse/JBAS-4205 .

       

      In the past I've solved similar problems for the web module by adding a dependency (<depends>jboss.jca:service=DataSourceBinding,name=my_ds</depends>) to the jboss-web.xml of such web module.

       

      Is there any equivalent for the EJB module that allows me to express such a dependency? jboss-ejb.xml or something like that?

       

      Thanks in advance for all help!

        • 1. Re: Nested DataSource fails to deploy before ejbs
          jaikiran pai Master

          There's the jboss.xml (for ejb jar files) where you can add dependencies per bean (i.e. a bean can be configured to depend on something else through the use of <depends>). But since you mention that it's the persistence.xml which requires this datasource, then you can just add this dependency in your persistence.xml. See this http://www.jboss.org/file-access/default/members/jbossejb3/freezone/docs/reference/1.0.7/html/entityconfig.html which explains about:

           

          jboss.depends.{some arbitrary name} - Specify an MBean dependency for the persistence unit deployment. 

           

          So you can use:

           

          <?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="...">
                <jta-data-source>java:/DefaultDS</jta-data-source>
                ...
                <properties>
                      ... 
                    <property name="jboss.depends.1" value="jboss.test:service=YetAnotherDependedOn"/>
                </properties>
             </persistence-unit>
          </persistence>
          
          • 2. Re: Nested DataSource fails to deploy before ejbs
            henk de boer Master

            That looks very nice and is exactly what I was looking for. Thanks a bunch!

             

            Although I was originally thinking  about finding a way to let the entire EJB module wait for the datasource having been deployed, this seems to do the trick quite nicely. Since the deployment fails only occasionally (perhaps a race condition, perhaps a deployment error on my part), I can't test directly whether it solves my problems, but we'll see in the longer term.

             

            Wouldn't it btw be possible for JBoss AS to spot the dependency automatically? If persistence.xml declares using a specific datasource and JBoss AS is able to keep track of which datasources are already deployed, then it might attempt to look for undeployed datasources whenever it wants to start a persistence unit with a yet undeployed datasource.

             

            Would something like that be possible?

            • 3. Re: Nested DataSource fails to deploy before ejbs
              jaikiran pai Master

              henk53 wrote:

               


               

              Wouldn't it btw be possible for JBoss AS to spot the dependency automatically? If persistence.xml declares using a specific datasource and JBoss AS is able to keep track of which datasources are already deployed...

               

              Would something like that be possible?

              It does try to add a implicit dependency actually (AFAIK). And the document that i pointed to http://www.jboss.org/file-access/default/members/jbossejb3/freezone/docs/reference/1.0.7/html/entityconfig.html talks about a jboss.no.implicit.datasource.dependency property to "disable" this behaviour. The property description is as follows:

               

              jboss.no.implicit.datasource.dependency - JBoss tries to register deployment dependencies for datasource by 
              guessing the dependency name based on the jndi name of the datasource. Use this switch if the guess is wrong. 
              

               

              I think the persistence module is not able to "guess" the datasource dependency MBean ObjectName correctly because you have packaged the -ds.xml within your .ear - which i think results in a different MBean ObjectName than if you had deployed it directly in deploy folder.