1 Reply Latest reply on Apr 2, 2009 6:54 PM by Arbi Sookazian

    Make JNDI datasource visible to Seam

    Alex Cougarman Apprentice

      Hi. We've got a datasource defined in a file in the Deploy folder of JBoss server: oracleDev-system-ds.xml. The file's contents are below. How do I reference this datasource from within Seam? Each time I create a Seam app via the New Seam Project wizard, it wants to create a connection and there doesn't seem to be any way to tell it to use this JNDI name webappconn.


      What am I doing wrong? Thanks.



      <?xml version="1.0" encoding="UTF-8"?>
      <datasources>
        <local-tx-datasource>
          <jndi-name>webappconn</jndi-name>
          <connection-url>jdbc:oracle:thin:@server:1521:dev</connection-url>
          <driver-class>oracle.jdbc.driver.OracleDriver</driver-class>
          <user-name>webuser</user-name>
          <password>*******</password>
          <exception-sorter-class-name>org.jboss.resource.adapter.jdbc.vendor.OracleExceptionSorter
          </exception-sorter-class-name>
          <metadata>
         <type-mapping>Oracle10g</type-mapping>
          </metadata>
        </local-tx-datasource>
      </datasources>


        • 1. Re: Make JNDI datasource visible to Seam
          Arbi Sookazian Master

          Here is an example using Oracle:


          foo-ds.xml:


          <datasources>
             <local-tx-datasource>
                <jndi-name>InternalJavaWebAppTemplateDatasource</jndi-name>
                <connection-url>jdbc:oracle:thin:@catlmsxd215v.corp.cox.com:1521:DFLDOLTP</connection-url>
                <driver-class>oracle.jdbc.driver.OracleDriver</driver-class>
                <user-name>ijwat</user-name>
                <password>ijwat</password>
             </local-tx-datasource>
              
          </datasources>



          persistence.xml:


          <persistence-unit name="InternalJavaWebAppTemplate">
                <provider>org.hibernate.ejb.HibernatePersistence</provider>
                <jta-data-source>java:/InternalJavaWebAppTemplateDatasource</jta-data-source>
                <properties>
                   <property name="hibernate.dialect" value="org.hibernate.dialect.Oracle10gDialect"/>
                   <property name="hibernate.hbm2ddl.auto" value="validate"/>
                   <property name="hibernate.show_sql" value="true"/>
                   <property name="hibernate.format_sql" value="true"/>
                   <property name="jboss.entity.manager.factory.jndi.name" value="java:/InternalJavaWebAppTemplateEntityManagerFactory"/>
                </properties>
             </persistence-unit>



          components.xml:


          <persistence:managed-persistence-context name="entityManager"
                                               auto-create="true"                                     
                                persistence-unit-jndi-name="java:/InternalJavaWebAppTemplateEntityManagerFactory"/>



          This is how we accomplish this with MSSQL (it's very similar with Oracle):


          foo-ds.xml:


          <datasources>
             
             <local-tx-datasource>
                <jndi-name>boBETSDatasource</jndi-name>
                <connection-url>jdbc:sqlserver://CORG0DB901:1433;databaseName=boBETS</connection-url>
                <driver-class>com.microsoft.sqlserver.jdbc.SQLServerDriver</driver-class>
                <user-name>_AppUser_JavaTestAcct</user-name>
                <password>JavaTestAcct</password>     
             </local-tx-datasource>
          </datasource>



          persistence.xml:


             <persistence-unit name="boBETS">
                <provider>org.hibernate.ejb.HibernatePersistence</provider>
                <jta-data-source>java:/boBETSDatasource</jta-data-source>
                <properties>
                   <property name="hibernate.dialect" value="org.hibernate.dialect.SQLServerDialect"/>
                   <!-- <property name="hibernate.hbm2ddl.auto" value="validate"/>   -->
                   <property name="hibernate.show_sql" value="true"/>
                   <property name="hibernate.format_sql" value="true"/>
                   <property name="jboss.entity.manager.factory.jndi.name" value="java:/boBETSEntityManagerFactory"/>
                   <property name="hibernate.default_catalog" value="boBETS"/>
                   <property name="hibernate.default_schema" value="dbo"/>
                </properties>
             </persistence-unit>



          components.xml:


             <persistence:managed-persistence-context name="entityManager"
                                               auto-create="true"
                                persistence-unit-jndi-name="java:/boBETSEntityManagerFactory"/>  



          This is assuming that you will be injecting SMPC as follows:


          @Name("testFoo")
          public class testFooBean
          {
              @In EntityManager entityManager;
              ....
          }
          



          Remember that the instance name of the EntityManager injection must match the name attribute for the <persistence:managed-persistence-context> tag