8 Replies Latest reply: Jun 6, 2012 1:37 PM by span7152 RSS

    How to configure JBoss to connect to 2 databases?

    span7152 Newbie

      Hi,

       

         I am configuring JBoss-5.1.0.GA to connect to 2 databses

         Anybody have the example for 2 databases in server/default/conf/login-config.xml and server/default/deply/messaging/oracle-persistence-service.xml?

       

      Thanks.

        • 1. Re: How to configure JBoss to connect to 2 databases?
          Wolf-Dieter Fink Master

          You need two configurations of datasources i.e. two *-ds.xml files.

          Whithin the messaging persistence service or other services you reference the (JNDI) name of the datasource.

          • 2. Re: How to configure JBoss to connect to 2 databases?
            span7152 Newbie

            Mr. Wolf-Dieter,

             

            I've done following steps before trying

            Copied “ojdbc14.jar” into server/default/lib dir.

            Removed “hsqldb-ds.xml” from server/default/deploy dir.

            Removed “hsqldb.jar” and “hsqldb-plugin.jar” from common/lib dir.

            Removed HsqlDbRealm from “login-confgi.xml”.

            Added "OracleDbRealm" into login-config.xml

            Fixed web.xml, jboss-web.xml, META-INF/jbosscmp-jdbc.xml.

             

             

             

            Please see 2 attemps as below. I need more instructions.

               (1) Split “oracle-xa-ds.xml” into “oracleds1-xa-ds.xml” for OracleDS1 and “oracleds2-xa-ds.xml” for OracleDS2.

             

            oracleds1-xa-ds.xml:

            <?xml version="1.0" encoding="UTF-8"?>

            <datasources>

               <xa-datasource>

                  <jndi-name>jdbc/OracleDS1</jndi-name>

                  <!-- use-java-context>false</use-java-context -->

                  <track-connection-by-tx>true</track-connection-by-tx>

                  <isSameRM-override-value>false</isSameRM-override-value>

                  <xa-datasource-class>oracle.jdbc.xa.client.OracleXADataSource</xa-datasource-class>

                  <xa-datasource-property name="URL">URL</xa-datasource-property>

                    <xa-datasource-property name="User">User</xa-datasource-property>

                  <xa-datasource-property name="Password">Password</xa-datasource-property>     

                  <exception-sorter-class-name>org.jboss.resource.adapter.jdbc.vendor.OracleExceptionSorter</exception-sorter-class-name>

                    <no-tx-separate-pools/>

                 

                  <metadata>

                     <type-mapping>Oracle9i</type-mapping>

                  </metadata>

               </xa-datasource>

              

                <mbean code="org.jboss.resource.adapter.jdbc.vendor.OracleXAExceptionFormatter"

                              name="jboss.jca:service=OracleXAExceptionFormatter">

                    <depends optional-attribute-name="TransactionManagerService">

                        jboss:service=TransactionManager

                    </depends>

                </mbean>     

            </datasources>

             

            oracleds2-xa-ds.xml:

            <?xml version="1.0" encoding="UTF-8"?>

               <xa-datasource>

                  <jndi-name>jdbc/OracleDS2</jndi-name>

                  <!-- use-java-context>false</use-java-context -->

                  <track-connection-by-tx>true</track-connection-by-tx>

                  <isSameRM-override-value>false</isSameRM-override-value>

                  <xa-datasource-class>oracle.jdbc.xa.client.OracleXADataSource</xa-datasource-class>

                  <xa-datasource-property name="URL">URL</xa-datasource-property>

                    <xa-datasource-property name="User">User</xa-datasource-property>

                  <xa-datasource-property name="Password">Password</xa-datasource-property>

                    <security-domain>OracleDbRealm</security-domain>

                    <security-domain-and-application>OracleDbRealm</security-domain-and-application>     

                  <exception-sorter-class-name>org.jboss.resource.adapter.jdbc.vendor.OracleExceptionSorter</exception-sorter-class-name>

                  <no-tx-separate-pools/>

                 

                   <metadata>

                     <type-mapping>Oracle9i</type-mapping>

                  </metadata>

             

               </xa-datasource>  

              

                <mbean code="org.jboss.resource.adapter.jdbc.vendor.OracleXAExceptionFormatter"

                              name="jboss.jca:service=OracleXAExceptionFormatter">

                    <depends optional-attribute-name="TransactionManagerService">

                        jboss:service=TransactionManager

                    </depends>

                </mbean>     

            </datasources>

             

             

             

            At the same time, split “oracle-persistence-service.xml” into “oracleds1-persistence-service.xml” for OracleDS1 and

            “oracleds2-persistence-service.xml” for topmisOracleDS2.

             

            oracleds1-persistence-service.xml:

               <!-- Persistence Manager MBean configuration

                   ======================================== -->

             

               <mbean code="org.jboss.messaging.core.jmx.JDBCPersistenceManagerService"

                  name="jboss.messaging:service=PersistenceManager"

                  xmbean-dd="xmdesc/JDBCPersistenceManager-xmbean.xml">

             

                  <depends>jboss.jca:service=DataSourceBinding,name=jdbc/OracleDS1</depends>

             

                  <depends optional-attribute-name="TransactionManager">jboss:service=TransactionManager</depends>

             

                  <!-- The datasource to use for the persistence manager -->

             

                  <attribute name="DataSource">java:jdbc/OracleDS1</attribute>

                  ...........

              </mbean>

             

            oracleds2-persistence-service.xml:

               <!-- Persistence Manager MBean configuration

                   ======================================== -->

             

               <mbean code="org.jboss.messaging.core.jmx.JDBCPersistenceManagerService"

                  name="jboss.messaging:service=PersistenceManager"

                  xmbean-dd="xmdesc/JDBCPersistenceManager-xmbean.xml">

             

                  <depends>jboss.jca:service=DataSourceBinding,name=jdbc/OracleDS2</depends>

             

                  <depends optional-attribute-name="TransactionManager">jboss:service=TransactionManager</depends>

             

                  <!-- The datasource to use for the persistence manager -->

             

                  <attribute name="DataSource">java:jdbc/OracleDS2</attribute>

                  ...........

              </mbean>

             

            Got a lot of warning/error

             

            messages like "

            WARN  [AbstractDeploymentContext] Unable to register deployment mbean jboss.messaging:service=PersistenceManager
            javax.management.InstanceAlreadyExistsException: jboss.deployment:id="jboss.messaging:service=PersistenceManager",type=Component already registered.

             

            (2)

             

            Restored to one file “oracle-persistence-service.xml” with “DefaultDS”. 

            <mbean code="org.jboss.messaging.core.jmx.JDBCPersistenceManagerService"

                  name="jboss.messaging:service=PersistenceManager"

                  xmbean-dd="xmdesc/JDBCPersistenceManager-xmbean.xml">

             

                  <depends>jboss.jca:service=DataSourceBinding,name=DefaultDS</depends>

             

                  <depends optional-attribute-name="TransactionManager">jboss:service=TransactionManager</depends>

             

                  <!-- The datasource to use for the persistence manager -->

             

                  <attribute name="DataSource">java:DefaultDS</attribute>

                  ...........

              </mbean>

             

            Got the following warning/error messages:

            09:48:13,007 WARN  [TransactionManagerService] XAExceptionFormatters are not supported by the JBossTS Transaction Service - this warning can safely be ignored
            09:48:13,725 INFO  [ConnectionFactoryBindingService] Bound ConnectionManager 'jboss.jca:service=DataSourceBinding,name=jdbc/topmisDS' to JNDI name 'java:jdbc/topmisDS'
            09:48:13,732 WARN  [AbstractDeploymentContext] Unable to register deployment mbean jboss.jca:service=OracleXAExceptionFormatter
            javax.management.InstanceAlreadyExistsException: jboss.deployment:id="jboss.jca:service=OracleXAExceptionFormatter",type=Component already registered.

            • 3. Re: How to configure JBoss to connect to 2 databases?
              Wolf-Dieter Fink Master

              You should remove one MBean OracleXAExceptionFormatter because it must not registered twice.

              Also you need only one JDBCPersistenceManager for messaging, so remove oracleds2-persistence-service.xml

              • 4. Re: How to configure JBoss to connect to 2 databases?
                span7152 Newbie

                Mr. Wold-Dieter,

                 

                   Can we write oracleds-persistence-service.xml as follows? (Not sure???)

                 

                   <!-- Persistence Manager MBean configuration

                       ======================================== -->

                 

                   <mbean code="org.jboss.messaging.core.jmx.JDBCPersistenceManagerService"

                      name="jboss.messaging:service=PersistenceManager"

                      xmbean-dd="xmdesc/JDBCPersistenceManager-xmbean.xml">

                      <depends>jboss.jca:service=DataSourceBinding,name=jdbc/OracleDS1</depends>

                 

                      <depends>jboss.jca:service=DataSourceBinding,name=jdbc/OracleDS2</depends>

                 

                      <depends optional-attribute-name="TransactionManager">jboss:service=TransactionManager</depends>

                 

                      <!-- The datasource to use for the persistence manager -->

                      <attribute name="DataSource">java:jdbc/OracleDS1</attribute>

                 

                      <attribute name="DataSource">java:jdbc/OracleDS2</attribute>

                      ...........

                  </mbean>

                 

                Thanks,

                • 5. Re: How to configure JBoss to connect to 2 databases?
                  Wolf-Dieter Fink Master

                  No,

                  it is not possible to have more than one persistence for the messaging system.

                  Also I don't see a need for that.

                  • 6. Re: How to configure JBoss to connect to 2 databases?
                    span7152 Newbie

                    Mr. Wolf-Dieter,

                     

                       Thank you for your information.

                       One more assoicted question. How to put 2 <security-domain> in "jboss-web.xml" because of 2 databases?

                       The loing-config is as follows:

                         <application-policy name="oracleds1">
                        <authentication>
                          <login-module code="org.jboss.security.auth.spi.UsersRolesLoginModule"
                            flag="required">
                            <module-option name="usersProperties">props/oracleds1-users.properties</module-option>
                            <module-option name="rolesProperties">props/oracleds1-roles.properties</module-option>
                          </login-module>
                        </authentication>
                      </application-policy>
                       
                      <application-policy name="oracleds2">
                        <authentication>
                          <login-module code="org.jboss.security.auth.spi.UsersRolesLoginModule"
                            flag="required">
                            <module-option name="usersProperties">props/oracleds2-users.properties</module-option>
                            <module-option name="rolesProperties">props/oracleds2-roles.properties</module-option>
                          </login-module>
                        </authentication>
                      </application-policy>

                    • 7. Re: How to configure JBoss to connect to 2 databases?
                      Wolf-Dieter Fink Master

                      I'm not sure what you mean. As far as I know the web.xml can only contain one security-domain.

                      But this is a different issue I would recommend to mark this thread as answered and open a new one because you might get a better answer if you post with a better subject into the right forum.

                      • 8. Re: How to configure JBoss to connect to 2 databases?
                        span7152 Newbie

                        Thanks! Will open one new thread.