6 Replies Latest reply on Mar 27, 2008 10:26 AM by chenww

    Dynamic deployment for EJB3 component

      I have a standalone component that consists of some EJB3 entities and statelss beans. How can I deploy this component to different Jboss systems which may have different data sources defined already? I assume this component does not bundle with its own database and data source and would like share with whatever data source available on the system.

      I tried to create EntityManagerFactory manually but no way to dynamic specify unit name or persistence provider.

      If use Persistence.xml way, the unit name and data source are static.

      Pls help

        • 1. Re: Dynamic deployment for EJB3 component
          frankthetank

          That should not be a problem if you make sure to have your data sources configured with one unique jndi-name.

          Yes, the jndi name in the persistence.xml is static, but it does a name lookup and as long as your *-ds.xml maps the database to the same name, it could just work.

          Just note that this presumes that only *one* *-ds.xml uses that jndi name.

          • 2. Re: Dynamic deployment for EJB3 component

            Frank,

            I can see this point, but I have no control how the data source named and JNDI registered as they are from different products. All I can is let them tell my component what is their datasources and where are them. Now even I got these information, I have no way to inject into the EntityManagerFactory or Persistence layer.

            Thanks

            • 3. Re: Dynamic deployment for EJB3 component
              frankthetank

              Actually you can change the names to whatever you want.
              They just have to match in the areas I have listed below.

              Check your [database]-ds.xml (located in your deploy dir) and look for a tag <jndi-name>SomeName</jndi-name>.

              That is the name under which the datasource registers itself.

              That name is also used in the persistence.xml located under .
              <jta-data-source>java:/SomeName</jta-data-source>

              Just make sure the two names are the same (copy & paste it .. trust me ;) ).

              Or, maybe I am not getting it. Just to verify the setup:
              You have a [database]-ds.xml in your deploy directory and a persistance.xml in your [project]/META-INF/ dir.

              It is also probably also just have two *-ds.xmls in your deploy directory giving you access to the database. Just tried it and at least they both register themselves.

              You can even have a per-database-level in the *-ds.xml.

              Make sure the file name and the JNDI names are different then the first.

              • 4. Re: Dynamic deployment for EJB3 component

                Frank,

                Maybe my explaination is not clear enough. The problem I am having now is my component does not know the data source JNDI name upfront until at deployment time. I can not endure other products will deploy a data source with the JNDI name exactly match what I defined in persistence.xml, but I can ask for the data source name from them at deployment time. However, there is no way I can set the data source name dynamically from persistence API.

                Thanks

                • 5. Re: Dynamic deployment for EJB3 component
                  frankthetank

                  Dumb question and not trying to be a jerk, but why do you have to wait until deployment time?

                  Who is the 'other products'?

                  So if I understand you correctly, you only supply the component and otherwise have zero access or control over the rest of the jboss?

                  Then that is not so good ;)

                  My original idea was to have you hardcode your jndi source name and then add a *-ds.xml to the deployment.

                  A brute force might be to write your own *-ds.xml into the deploy dir, but I have no idea if that is even possible.

                  I have similar issues, but I need to switch data sources at runtime.

                  I think we need some kind of dynamic data source system.

                  Sorry for the lack of help.

                  • 6. Re: Dynamic deployment for EJB3 component

                    It's a component and could be integrate with a variety of products, but the huge data volume makes web service not a good candidate in such a case. While lack of pointing to a different data source at deployment time, it is a big gap to enable componentize in EJB3 environment. We do not expect to change data source at runtime, but at deployment time.