5 Replies Latest reply on Dec 17, 2008 12:03 PM by jorge ciombalo

    Dynamic units within persistence.xml

    Kevin Hilton Newbie

      I have come across a problem with developing using EJB3.0, the software I am currently upgrading requires the ability to add dymanic persistence-unit entries within persistence.xml at run time.

      The problem is (and there is no way around this as it is a live system on multiple sites) datasources can be added to JBOSS at any point, these datasources act as separate company databases.

      What I'm basically asking for is this, does anyone know of a way of dynamically creating an EntityManager without specifying the information within the persistence.xml file. I have all the information which is needed such as the datasource, but cannot find a way of achieving this other than creating a unlimited list of persistence units.

      Please help.

        • 1. Re: Dynamic units within persistence.xml
          Emmanuel Bernard Master

          Create an Ejb3Configuration() object and populate it, then create the EMF from it

          • 2. Re: Dynamic units within persistence.xml
            Kevin Hilton Newbie

             

            "epbernard" wrote:
            Create an Ejb3Configuration() object and populate it, then create the EMF from it


            Nice one.

            I can create an entity manager, the only problem I now have is the jar dependancies require a different relative path to dependancy injection. I can hard code the full path and it works OK, but we have customers on a host of different servers / operating systems.

            • 3. Re: Dynamic units within persistence.xml
              Emmanuel Bernard Master

              Hum, I don't think I can solve that.

              • 4. Re: Dynamic units within persistence.xml
                Olivier Vincent Newbie

                Hello,
                I exactly have the same problem !
                Have you found a solution ?

                Thanks,

                Olivier

                • 5. Re: Dynamic units within persistence.xml
                  jorge ciombalo Newbie

                  Hi guys,

                  I had created a factory class that use Ejb3Configuration to add the dynamic persistent-units.

                  I tried to test connecting to a DS db001ds and made a persist and a find operation successfully.

                  But when I try to create 2 EntityManagerFactory's, (DS db001ds and db002ds) i get the following warn:

                  ...
                  14:09:45,953 INFO [DatasourceConnectionProvider] Using datasource: java:/db002ds
                  14:09:45,984 WARN [loggerI18N] [com.arjuna.ats.internal.jta.transaction.arjunacore.lastResource.disallow] [com.arjuna.ats.internal.jta.transaction.arjunacore.lastResource.disallo
                  w] Adding multiple last resources is disallowed. Current resource is org.jboss.resource.connectionmanager.TxConnectionManager$LocalXAResource@1bc6b34
                  14:09:46,000 WARN [SettingsFactory] Could not obtain connection metadata
                  org.jboss.util.NestedSQLException: Could not enlist in transaction on entering meta-aware object!; - nested throwable: (javax.transaction.SystemException: java.lang.Throwable: Una
                  bled to enlist resource, see the previous warnings. tx=TransactionImple < ac, BasicAction: -3f57ffbb:5b6:49492433:65 status: ActionStatus.ABORT_ONLY >); - nested throwable: (org.j
                  boss.resource.JBossResourceException: Could not enlist in transaction on entering meta-aware object!; - nested throwable: (javax.transaction.SystemException: java.lang.Throwable:
                  Unabled to enlist resource, see the previous warnings. tx=TransactionImple < ac, BasicAction: -3f57ffbb:5b6:49492433:65 status: ActionStatus.ABORT_ONLY >))
                   at org.jboss.resource.adapter.jdbc.WrapperDataSource.getConnection(WrapperDataSource.java:95)
                  ...
                  


                  And any subsequent call to the EntityManager of db002ds throws the same message, but now like error and not warn.

                  Someone had used Ejb3Configuration without trouble to connect in multiple persistent units?
                  Thanks for your time,

                  Jorge