1 Reply Latest reply on Jun 9, 2009 7:19 PM by gonorrhea

    SMPC and PersistenceUnit relationship

    gonorrhea

      Typically we have one PersistenceUnit configured in persistence.xml.  And we have one SMPC configured in components.xml.  So that's a 1:1 relationship.  Assume one local db configured in foo-ds.xml (and both of the PUs are pointing to that one <local-tx-datasource>).


      What about a scenario where you have two SMPCs defined in your components.xml which are using the same foo-ds.xml?  Should we configure another PU in persistence.xml for the 2nd SMPC?  Or is it ok to use the same PU for both SMPCs that are using the same db?

        • 1. Re: SMPC and PersistenceUnit relationship
          gonorrhea

          Here is a concrete example...


          persistence-dev.xml:



          <?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="EquipmentRecovery">
                <provider>org.hibernate.ejb.HibernatePersistence</provider>
                <jta-data-source>java:/EquipmentRecoveryDatasource</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="hibernate.generate_statistics" value="true"/>
                   <property name="jboss.entity.manager.factory.jndi.name" value="java:/EquipmentRecoveryEntityManagerFactory"/>
                   <property name="hibernate.default_catalog" value="EquipmentRecovery"/>
                   <property name="hibernate.default_schema" value="dbo"/>
                </properties>
             </persistence-unit>
          </persistence>



          foo-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>EquipmentRecoveryDatasource</jndi-name>
                <connection-url>jdbc:sqlserver://CORG0DB901:1433;databaseName=EquipmentRecovery</connection-url>
                <driver-class>com.microsoft.sqlserver.jdbc.SQLServerDriver</driver-class>
                <user-name>_AppUser_JavaTestAcct</user-name>
                <password>JavaTestAcct</password>     
             </local-tx-datasource>
          </datasources>



          components.xml snippet:


          <persistence:managed-persistence-context name="entityManager"
                                               auto-create="true"
                                persistence-unit-jndi-name="java:/EquipmentRecoveryEntityManagerFactory"/> 
             
             <!-- use entityManagerSupport for modalPanels only -->
             
                       
             <persistence:managed-persistence-context name="entityManagerSupport"
                                               auto-create="true"
                                persistence-unit-jndi-name="java:/EquipmentRecoveryEntityManagerFactory"/>        
          



          And yes, there is a specific scenario which requires me to ask this question which is related to the topics I've posted recently with one LRC, atomic conversastions, isolated SMPCs (Hibernate manual flush) and using modalPanels with embedded editable forms in one xhtml/JSF page.