9 Replies Latest reply on Nov 11, 2005 2:34 PM by Khoya Raaz

    How to deploy a data source inside an archive on 4.0.3?

    Peter Salomonsen Newbie

      Earlier with Jboss 4.0.1 and EJB3.0 Pre5 it was possible to include a custom ds.xml inside the ejb3 archive. This doesn't work anymore (on 4.0.3 with EJB3 Beta) - not even when packaging according to the official spec - inside an ear.

      What seems to happen is that JBOSS deploys the entity beans and tries to access the datasource which is not yet registered. In the previous version the datasource was registered first, but now it seems to be registered after the entity beans.

      A resolution - but not a very good looking one - is to deploy a seperate archive including the ds.xml and the databasedriver (i.e. mysql). Then after this is deployed and registered, deploy the entity bean archive - and then it works.

      However the deployment order is not guaranteed when restarting the app server. And therefore this workaround does not work in production environments.

      Have I done everything wrong, or is it something wrong in this new version?

      Best regards,

      Peter Salomonsen

        • 1. Re: How to deploy a data source inside an archive on 4.0.3?
          Kabir Khan Master

          If you go to the JMX console, you should find your datasource listed. It's ObjectName should be something like:

          jboss.jca:service=DataSourceBinding,name=MYDSNAME


          You can use the @org.jboss.annotation.ejb.Depends annotation to specify dependencies on other services.

          Example:

          @Stateless
          @Depends ("jboss.jca:service=DataSourceBinding,name=MYDSNAME")
          public class MyBean implements ....
          {

          ]

          See the Service bean tutorial example for more information regarding Depends.

          • 2. Re: How to deploy a data source inside an archive on 4.0.3?
            Jon Åkerström Newbie

            I'm having similiar problems with packaging under 4.0.3 and I wonder how the @Depends attribute solves the case when you have a .ear with one .war, one .sar that contains the definition of a database login module that requires a DS and a .par which contains the persistence.xml and some ejb's.
            In my case no matter what the application.xml says the ejbs inside of the .par always gets deployed first and therefore the DS is not registered until after the ejb's are deployed (which uses Default DS instead of the one defined inside of the .par in persistence.xml).
            Note that im not using any .ejb3 extension since that seems to have the effect that the default DS is always used.

            There must be a more smooth way to solve this? I have two datasources defined in the persistence.xml inside the .par, and in the stateless session beans i want to use them both with the @PersistenceContext attribute, but the real issue is that I cant get the datasources and their entity managers to be registered prior to the .sar and the ejb's inside of the .par since the ejbs inside of the .par always - with no exception is deployed before the actual DS definition in the persistence.xml.

            Best regards
            Jon Åkerström

            • 3. Re: How to deploy a data source inside an archive on 4.0.3?
              Peter Salomonsen Newbie

              A service bean seems to solve the dependency issue for that particular service bean. But it still seams that the parsing of persistence.xml takes place before the datasource is bound. And so all my entitybeans crashes. Does this mean I have to put a depends annotation on every bean? It would be better to set the dependency in i.e. jboss.xml - but somehow that file doesn't seem to be processed during deployment...

              22:57:07,013 INFO [Ejb3Module] Found persistence.xml file in EJB3 jar
              22:57:07,052 INFO [Configuration] processing extends queue
              22:57:07,052 INFO [Configuration] processing collection mappings
              22:57:07,053 INFO [Configuration] processing association property references
              22:57:07,053 INFO [Configuration] processing foreign key constraints
              22:57:07,093 INFO [Configuration] processing extends queue
              22:57:07,093 INFO [Configuration] processing collection mappings
              22:57:07,093 INFO [Configuration] processing association property references
              22:57:07,093 INFO [Configuration] processing foreign key constraints
              22:57:07,094 INFO [NamingHelper] JNDI InitialContext properties:{}
              22:57:07,107 FATAL [DatasourceConnectionProvider] Could not find datasource: java:LMCMSDS
              javax.naming.NameNotFoundException: LMCMSDS not bound
              at org.jnp.server.NamingServer.getBinding(NamingServer.java:491)
              at org.jnp.server.NamingServer.getBinding(NamingServer.java:499)
              at org.jnp.server.NamingServer.getObject(NamingServer.java:505)
              at org.jnp.server.NamingServer.lookup(NamingServer.java:278)

              • 4. Re: How to deploy a data source inside an archive on 4.0.3?
                Bill Burke Master

                -ds.xml files should be deployed before EJB3's and .PARs. I'll add a jira task.

                • 5. Re: How to deploy a data source inside an archive on 4.0.3?
                  asael Newbie

                  I saw that this JIRA was closed but the issue still exists.
                  ( http://jira.jboss.com/jira/browse/EJBTHREE-205 )

                  Simply think of an EAR with a datasource. The EAR deployer will first deploy the par wher it finds the reference to the datasource but the datasource hasn't been deployed yet ?

                  Or are there any workarounds?

                  • 6. Re: How to deploy a data source inside an archive on 4.0.3?
                    asael Newbie

                    Sorry clicked submit too fast.

                    But I think the dependency shouldn't be on the persistence object. How about adding a kind of depends child in the application.xsd of ejb ?

                    Or even a default depends if a entitymanager is referenced ?

                    • 7. Re: How to deploy a data source inside an archive on 4.0.3?
                      Bill Burke Master

                      The ds.xml file should be deployed before ejb3, not sure why its not. I'll look into it.

                      But I should do this:

                      I'll set up a dependency between:

                      1) The entity manager and the datasource
                      2) the EJB and the entity-manager

                      Eventually, i'll add one between the war and the EM too.

                      BTW, not sure why I closed the bug the first time. Sorry!

                      • 8. Re: How to deploy a data source inside an archive on 4.0.3?
                        asael Newbie

                        I think everything would work fine when simply the datasource is bound before the .par is deployed.

                        Lets close this one and do the rest on this topic -->
                        http://www.jboss.com/index.html?module=bb&op=viewtopic&t=69457

                        Because there you added the JIRA etc

                        • 9. Re: How to deploy a data source inside an archive on 4.0.3?
                          Khoya Raaz Newbie

                           

                          "pesalomo" wrote:
                          A service bean seems to solve the dependency issue for that particular service bean. But it still seams that the parsing of persistence.xml takes place before the datasource is bound. And so all my entitybeans crashes. Does this mean I have to put a depends annotation on every bean? It would be better to set the dependency in i.e. jboss.xml - but somehow that file doesn't seem to be processed during deployment...

                          22:57:07,013 INFO [Ejb3Module] Found persistence.xml file in EJB3 jar
                          22:57:07,052 INFO [Configuration] processing extends queue
                          22:57:07,052 INFO [Configuration] processing collection mappings
                          22:57:07,053 INFO [Configuration] processing association property references
                          22:57:07,053 INFO [Configuration] processing foreign key constraints
                          22:57:07,093 INFO [Configuration] processing extends queue
                          22:57:07,093 INFO [Configuration] processing collection mappings
                          22:57:07,093 INFO [Configuration] processing association property references
                          22:57:07,093 INFO [Configuration] processing foreign key constraints
                          22:57:07,094 INFO [NamingHelper] JNDI InitialContext properties:{}
                          22:57:07,107 FATAL [DatasourceConnectionProvider] Could not find datasource: java:LMCMSDS
                          javax.naming.NameNotFoundException: LMCMSDS not bound
                          at org.jnp.server.NamingServer.getBinding(NamingServer.java:491)
                          at org.jnp.server.NamingServer.getBinding(NamingServer.java:499)
                          at org.jnp.server.NamingServer.getObject(NamingServer.java:505)
                          at org.jnp.server.NamingServer.lookup(NamingServer.java:278)