1 Reply Latest reply on Dec 17, 2008 1:27 PM by kanwar sangha

    EntityManager on distributed database

    kanwar sangha Newbie

      Hi,


      We used seam-gen to do a CRUD app. We have two databases


      1) local  (on same box where app is deployed)
      2) remote (seperate box)


      We have 2 entities


      1) entity 1 - local db
      2) entity 2 - remote db



      Now when we try to access the entity2, we are getting db table not found exception. Basically the entityManager is quering the local db instead of the remote db.


      hss - remote db
      mnode  - local db




      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:transaction="http://jboss.com/products/seam/transaction"
                  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                  xsi:schemaLocation=
                      "http://jboss.com/products/seam/core http://jboss.com/products/seam/core-2.1.xsd 
                       http://jboss.com/products/seam/persistence http://jboss.com/products/seam/persistence-2.1.xsd 
                       http://jboss.com/products/seam/drools http://jboss.com/products/seam/drools-2.1.xsd
                       http://jboss.com/products/seam/bpm http://jboss.com/products/seam/bpm-2.1.xsd
                       http://jboss.com/products/seam/transaction http://jboss.com/products/seam/transaction-2.1.xsd
                       http://jboss.com/products/seam/security http://jboss.com/products/seam/security-2.1.xsd
                       http://jboss.com/products/seam/mail http://jboss.com/products/seam/mail-2.1.xsd
                       http://jboss.com/products/seam/components http://jboss.com/products/seam/components-2.1.xsd">
                       
          <core:init jndi-pattern="java:comp/env/sps/#{ejbName}/local" debug="false"/>    
      
          <transaction:ejb-transaction/>
      
          <core:manager conversation-timeout="120000" 
                        concurrent-request-timeout="120000"
                        conversation-id-parameter="cid"
                        parent-conversation-id-parameter="pid"/>
      
         <persistence:managed-persistence-context name="entityManagerHss"
                                           auto-create="true"
                                entity-manager-factory="#{hssEntityManagerFactory}"/>
      
         <persistence:entity-manager-factory name="hssEntityManagerFactory" 
                            persistence-unit-name="hss"/>   
                                       
                            
                            
           <persistence:managed-persistence-context name="entityManager"
                                           auto-create="true"
                                entity-manager-factory="#{mnodeEntityManagerFactory}"/>
      
         <persistence:entity-manager-factory name="mnodeEntityManagerFactory" 
                            persistence-unit-name="mnode"/>                      
                                 
         <security:identity authenticate-method="#{authenticator.authenticate}"/> 
      
          <!-- <security:identity authenticate-method="#{test.authenticate}"/> -->
          <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="2525" username="test" password="test" />
         <!-- For use with jBPM pageflow or process management -->
         <!--  
         <bpm:jbpm>
            <bpm:process-definitions></bpm:process-definitions>
            <bpm:pageflow-definitions></bpm:pageflow-definitions>
         </bpm:jbpm>
         -->
      </components>
      
      
      
      




      persistence.xml



      <?xml version="1.0" encoding="UTF-8"?>
      <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="mnode" transaction-type="JTA">
            <provider>org.hibernate.ejb.HibernatePersistence</provider>
            <jta-data-source>platformDatasource</jta-data-source>
            
            <properties>
               <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
               <property name="hibernate.show_sql" value="true"/>
               <property name="hibernate.format_sql" value="true"/>
               <property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.SunONETransactionManagerLookup"/>
            </properties>
         </persistence-unit>
           
           <persistence-unit name="hss" transaction-type="JTA">
            <provider>org.hibernate.ejb.HibernatePersistence</provider>
            <jta-data-source>hssDatasource</jta-data-source>
            
            <properties>
               <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
               <property name="hibernate.show_sql" value="true"/>
               <property name="hibernate.format_sql" value="true"/>
               <property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.SunONETransactionManagerLookup"/>
            </properties>
         </persistence-unit>
      </persistence>
      





      Entity 1



      @Entity
      @Table(name = visited_net, catalog = hss, uniqueConstraints = @UniqueConstraint(columnNames = "identity"))
      public class VisitedNetwork implements java.io.Serializable {
      
              private Integer id;
              private String identity;





      Entity 2



      @Entity
      @Table(name = Component, catalog = mnode_cm_data, uniqueConstraints = @UniqueConstraint(columnNames = "name"))
      public class Component implements java.io.Serializable {
      
              private int oidIndex;
              private ProtGrp protGrp;
      



      How to map the entity to an entityManager ??