3 Replies Latest reply on Nov 19, 2004 5:47 AM by lefou

    More than one datasource possible?

    lefou

      I want to migrate an existing EJB project, but it uses tree different datasources in the deployment descriptor.

      Now my Question: Is it possible to use more than one datasource under JBoss?

      My feeling is "no", because in jaws.xml you can only define a

      <datasource>java:/MySqlDS</datasource>
      <type-mapping>mySQL</type-mapping>

      and it seems, there is no possibility to add another on.

      Can anybody correct me, if I'm wrong, please.

        • 1. Re: More than one datasource possible?
          abrynils

          You can define datasources for the individual entity beans in the jbosscmp-jdbc.xml file or for each deployment unit using the default clause in the same file. I have no personal experience with this but it is listed in one of my books, "JBoss 3.0 Deployment and Administrator handbook" published by wrox. Thus you at least have a starting point to find information on the subject.

          Hope this is of help.
          regards,
          Anders

          • 2. Re: More than one datasource possible?

            We are using JBoss 3.2.x, and are currently connecting to two different databases in our EJB project. I believe that at JBoss 3.2.x only requires that the file containing your data sources be names as *-ds.xml. This file needs to be accessible from whereever your JBoss server scans for deployments. For example, we use the following mssql-ds.xml (for MS SQL Server), but again the name doesn't matter as long as it ends in -ds.xml:

            <datasources>
             <local-tx-datasource>
             <jndi-name>MSSQLDS-WMS</jndi-name>
             <connection-url>jdbc:microsoft:sqlserver://10.0.0.20:1433;DatabaseName=WMS;SelectMethod=Cursor</connection-url>
             <driver-class>com.microsoft.jdbc.sqlserver.SQLServerDriver</driver-class>
             </local-tx-datasource>
            
             <local-tx-datasource>
             <jndi-name>MSSQLDS-CUST</jndi-name>
             <connection-url>jdbc:microsoft:sqlserver://10.0.0.21:1433;DatabaseName=CUST;SelectMethod=Cursor</connection-url>
             <driver-class>com.microsoft.jdbc.sqlserver.SQLServerDriver</driver-class>
             </local-tx-datasource>
            </datasources>
            


            Note that our datasource declarations do not have username and password, but you can add those as well (we store username / password elsewhere).

            Hope this helps.

            Todd


            • 3. Re: More than one datasource possible?
              lefou

              Thanks, I will try that.

              Is it possible, to set different transaction levels for every data source?
              The (old) Inprise specific DD looks like this (only ds-part):

              <inprise-specific>
               <datasource>
               <jndi-name>jdbc/MTBDataSource</jndi-name>
               <url>jdbc:oracle:thin:@xx.xx.xx.xx:1521:memos</url>
               <username>xxx</username>
               <password>xxx</password>
               <isolation-level>TRANSACTION_READ_COMMITTED</isolation-level>
               <driver-class-name>oracle.jdbc.driver.OracleDriver</driver-class-name>
               </datasource>
               <datasource>
               <jndi-name>jdbc/MTB1DataSource</jndi-name>
               <url>jdbc:oracle:thin:@xx.xx.xx.xx:1521:memos</url>
               <username>xxx</username>
               <password>xxx</password>
               <isolation-level>TRANSACTION_SERIALIZABLE</isolation-level>
               <driver-class-name>oracle.jdbc.driver.OracleDriver</driver-class-name>
               </datasource>
               <datasource>
               <jndi-name>jdbc/MTBSecondSource</jndi-name>
               <url>jdbc:oracle:thin:@xx.xx.xx.xx:1521:memos</url>
               <username>xxx</username>
               <password>xxx</password>
               <isolation-level>TRANSACTION_NONE</isolation-level>
               <driver-class-name>oracle.jdbc.driver.OracleDriver</driver-class-name>
               </datasource>
               </datasource-definitions>
              </inprise-specific>


              You see, the different data soures are more a cosmetic way, to deal with the transaction/isolation level. Honestly, I don't know, how to set up the transaction level for a data soure in JBoss.

              lefou