0 Replies Latest reply on Sep 17, 2010 3:27 PM by Brian Sellden

    Multiple datasource/persistence-unit/EntityManagers in Seam app

    Brian Sellden Newbie

      Hello -

      I'm cringing slightly to post this because the issue has come up before.  I've read at least half a dozen threads on this and haven't found a solution.

      This is jboss-as 5.0.0.  I'm attempting to write a web app in Seam that allows a user to select an environment (a.k.a. database) to edit, and then move on to some pages that allow editing of the selected database.  My first approach is to create 2 data srouces, 2 persistence units, 2 entity manager factories and 2 entity managers.  I'm expecting that both entity managers will be injected into my java components so that I can select the proper one to use based on the users's selection of environment.  But things are failing during deployment, long before my java components are constructed.

      Starting at the bottom up, here's my CompanyCodeConfigurator-ds.xml:

      <?xml version="1.0" encoding="UTF-8"?>
      <!DOCTYPE datasources PUBLIC "-//JBoss//DTD JBOSS JCA Config 1.5//EN"
                                   "http://www.jboss.org/j2ee/dtd/jboss-ds_1_5.dtd">
      <datasources>
      <local-tx-datasource>
        <jndi-name>CompanyCodeConfiguratorDEVDatasource</jndi-name>
        <use-java-context>true</use-java-context>
        <connection-url>jdbc:oracle:thin:@bluefish:1521:XE</connection-url>
        <driver-class>oracle.jdbc.driver.OracleDriver</driver-class>
        <user-name>pafpuser</user-name>
        <password>pafpuser1</password>
        <min-pool-size>1</min-pool-size>
        <max-pool-size>4</max-pool-size>
      </local-tx-datasource>
      <local-tx-datasource>
        <jndi-name>CompanyCodeConfiguratorSITDatasource</jndi-name>
        <use-java-context>true</use-java-context>
        <connection-url>jdbc:oracle:thin:@10.1.8.121:1521:XE</connection-url>
        <driver-class>oracle.jdbc.driver.OracleDriver</driver-class>
        <user-name>pafpuser</user-name>
        <password>pafpuser1</password>
        <min-pool-size>1</min-pool-size>
        <max-pool-size>4</max-pool-size>
      </local-tx-datasource>
      </datasources>

       

      Here's the persistence.xml file:

      <?xml version="1.0" encoding="UTF-8"?>
      <!-- Persistence deployment descriptor for dev profile -->
      <persistence xmlns="http://java.sun.com/xml/ns/persistence"
                   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                   xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
                   version="1.0">
                               
        <persistence-unit name="CompanyCodeConfiguratorDEVpu">
            <provider>org.hibernate.ejb.HibernatePersistence</provider>
            <jta-data-source>java:CompanyCodeConfiguratorDEVDatasource</jta-data-source>
            <properties>
               <property name="hibernate.dialect" value="org.hibernate.dialect.Oracle10gDialect"/>
               <property name="hibernate.hbm2ddl.auto" value="create-drop"/>
               <property name="hibernate.show_sql" value="true"/>
               <property name="hibernate.format_sql" value="true"/>
               <property name="hibernate.default_schema" value="PAFPUSER"/>
               <property name="jboss.entity.manager.factory.jndi.name" value="java:/emfDEV"/>
            </properties>
         </persistence-unit>

         <persistence-unit name="CompanyCodeConfiguratorSITpu">
            <provider>org.hibernate.ejb.HibernatePersistence</provider>
            <jta-data-source>java:CompanyCodeConfiguratorSITDatasource</jta-data-source>
            <properties>
               <property name="hibernate.dialect" value="org.hibernate.dialect.Oracle10gDialect"/>
               <property name="hibernate.hbm2ddl.auto" value="create-drop"/>
               <property name="hibernate.show_sql" value="true"/>
               <property name="hibernate.format_sql" value="true"/>
               <property name="hibernate.default_schema" value="PAFPUSER"/>
               <property name="jboss.entity.manager.factory.jndi.name" value="java:/emfSIT"/>
            </properties>
         </persistence-unit>
                     
                   </persistence>

       

      And finally, components.xml:

      <?xml version="1.0" encoding="UTF-8"?>
      <components xmlns="http://jboss.com/products/seam/components"
      xmlns:core="http://jboss.com/products/seam/core" xmlns:persistence="http://jboss.com/products/seam/persistence"
      xmlns:drools="http://jboss.com/products/seam/drools" xmlns:bpm="http://jboss.com/products/seam/bpm"
      xmlns:security="http://jboss.com/products/seam/security" xmlns:mail="http://jboss.com/products/seam/mail"
      xmlns:web="http://jboss.com/products/seam/web" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://jboss.com/products/seam/core http://jboss.com/products/seam/core-2.2.xsd
                       http://jboss.com/products/seam/persistence http://jboss.com/products/seam/persistence-2.2.xsd
                       http://jboss.com/products/seam/drools http://jboss.com/products/seam/drools-2.2.xsd
                       http://jboss.com/products/seam/bpm http://jboss.com/products/seam/bpm-2.2.xsd
                       http://jboss.com/products/seam/security http://jboss.com/products/seam/security-2.2.xsd
                       http://jboss.com/products/seam/mail http://jboss.com/products/seam/mail-2.2.xsd
                       http://jboss.com/products/seam/web http://jboss.com/products/seam/web-2.2.xsd
                       http://jboss.com/products/seam/components http://jboss.com/products/seam/components-2.2.xsd">

      <core:init debug="@debug@" jndi-pattern="@jndiPattern@" />

      <core:manager concurrent-request-timeout="500"
        conversation-timeout="120000" conversation-id-parameter="cid"
        parent-conversation-id-parameter="pid" />

      <!--
        Make sure this URL pattern is the same as that used by the Faces
        Servlet
      -->
      <web:hot-deploy-filter url-pattern="*.seam" />

         <persistence:entity-manager-factory name="emfDEV"
            persistence-unit-name="companyCodeConfiguratorDEVpu" installed="false"/>

      <persistence:entity-manager-factory name="emfSIT"
            persistence-unit-name="companyCodeConfiguratorSITpu" installed="false"/>

      <persistence:managed-persistence-context
        name="emDEV" auto-create="true"
        entity-manager-factory="#{emfDEV}"
        persistence-unit-jndi-name="java:/CompanyCodeConfiguratorDEVpu" />

      <persistence:managed-persistence-context
        name="emSIT" auto-create="true"
        entity-manager-factory="#{emfSIT}"
        persistence-unit-jndi-name="java:/CompanyCodeConfiguratorSITpu" />

      <drools:rule-base name="securityRules">
        <drools:rule-files>
         <value>/security.drl</value>
        </drools:rule-files>
      </drools:rule-base>

      <security:rule-based-permission-resolver
        security-rules="#{securityRules}" />

      <security:identity authenticate-method="#{authenticator.authenticate}"
        remember-me="true" />

      <event type="org.jboss.seam.security.notLoggedIn">
        <action execute="#{redirect.captureCurrentView}" />
      </event>
      <event type="org.jboss.seam.security.loginSuccessful">
        <action execute="#{redirect.returnToCapturedView}" />
      </event>

      <mail:mail-session host="localhost" port="25" />

      </components>

       

      I'm happy to show the rather simple java components, but I just don't think I'm getting that far.  Here's the error:

      2010-09-17 13:31:36,890 ERROR [org.jboss.web.tomcat.service.deployers.TomcatDeployment] (HDScanner) ENC setup failed
      java.lang.NullPointerException
      at org.jboss.injection.PersistenceUnitHandler.getEntityManagerFactory(PersistenceUnitHandler.java:172)
      at org.jboss.injection.PersistenceUnitHandler.getFactory(PersistenceUnitHandler.java:163)
      at org.jboss.injection.PuEncInjector.inject(PuEncInjector.java:54)
      at org.jboss.web.tomcat.service.TomcatInjectionContainer.populateEnc(TomcatInjectionContainer.java:482)
      at org.jboss.web.tomcat.service.deployers.TomcatDeployment$EncListener.lifecycleEvent(TomcatDeployment.java:471)
      at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)
      at org.apache.catalina.core.StandardContext.start(StandardContext.java:4384)
      at org.jboss.web.tomcat.service.deployers.TomcatDeployment.performDeployInternal(TomcatDeployment.java:310)
      at org.jboss.web.tomcat.service.deployers.TomcatDeployment.performDeploy(TomcatDeployment.java:142)
      at org.jboss.web.deployers.AbstractWarDeployment.start(AbstractWarDeployment.java:461)
      at org.jboss.web.deployers.WebModule.startModule(WebModule.java:118)
      at org.jboss.web.deployers.WebModule.start(WebModule.java:97)

      Any help would be greatly appreciated.

       

      Regards -

       

      Brian.