1 Reply Latest reply on Jul 23, 2009 10:44 AM by jaikiran pai

    Problem creating self contained datasource and entity manger

    Mohit Anchlia Novice


      Jboss 4.2:

      We are currently having problems with getting EntityManager that is self contained only for .ear environment. Instead what is happening is that even though we have separate persistence.xml in each .ear file still entity manager is not becoming container specific. It's still getting loaded globally.

      Below is the persistence.xml in each .ear file. Datasource also is self contained inside the .ear file.

      
      <persistence>
       <persistence-unit name="EeEM" transaction-type="JTA">
       <provider>org.hibernate.ejb.HibernatePersistence</provider>
       <jta-data-source>java:/EeDS</jta-data-source>
       <properties>
       <property name="hibernate.dialect"
       value="org.hibernate.dialect.Oracle10gDialect"/>
      
       <!-- For debugging -->
       <!--
       <property name="hibernate.show_sql" value="true"/>
       -->
      
       <property name="hibernate.connection.driver_class"
       value="oracle.jdbc.OracleDriver"/>
      
       <!-- Workaround for Oracle 10G driver bug -->
       <property name="hibernate.jdbc.batch_size" value="0"/>
      
      
       <!-- Enable this is hibernate should be responsible for creating
       tables. -->
       <!--property name="hibernate.hbm2ddl.auto" value="create"/-->
       <property name="hibernate.connection.datasource" value="java:/EeDS"/>
       <property name="jboss.entity.manager.jndi.name" value="java:/EntityManagers/EeEM"/>
       <property name="jboss.entity.manager.factory.jndi.name" value="java:/EntityManagerFactories/EeEM"/>
       </properties>
       </persistence-unit>
      </persistence>
      
      


      
      <datasources>
       <local-tx-datasource>
       <jndi-name>EeDS</jndi-name>
       <track-connection-by-tx/>
       <connection-url>...</connection-url>
       <connection-property name="SetBigStringTryClob">true</connection-property>
       <!-- recommended by Oracle support to avoid ORA-01461 errors -->
       <connection-property name="oracle.jdbc.RetainV9LongBindBehavior">true</connection-property>
       <max-pool-size>@JDBC_MAX_POOL_SIZE@</max-pool-size>
       <driver-class>oracle.jdbc.OracleDriver</driver-class>
       <!-- Uses the pingDatabase method to check a connection is still valid before handing it out from the
       pool -->
       <valid-connection-checker-class-name>org.jboss.resource.adapter.jdbc.vendor.OracleValidConnectionChecker</valid-connection-checker-class-name>
       <!-- Checks the Oracle error codes and messages for fatal errors -->
       <exception-sorter-class-name>org.jboss.resource.adapter.jdbc.vendor.OracleExceptionSorter</exception-sorter-class-name>
       <!-- Oracles XA datasource cannot reuse a connection outside a transaction once enlisted in a global
      transaction and vice-versa -->
       <no-tx-separate-pools/>
       <!-- sql to call when connection is created
       <new-connection-sql>some arbitrary sql</new-connection-sql>
       -->
      
       <!-- sql to call on an existing pooled connection when it is obtained from pool - the OracleValidConn
      ectionChecker is prEered
       <check-valid-connection-sql>some arbitrary sql</check-valid-connection-sql>
       -->
      
       <!-- corresponding type-mapping in the standardjbosscmp-jdbc.xml (optional) -->
       <metadata>
       <type-mapping>Oracle9i</type-mapping>
       </metadata>
      
       <security-domain>EncryptedOracleDbRealm</security-domain>
       </local-tx-datasource>
      
      </datasources>
      
      


      Above .xml files lives inside each .ear file. Now I expect 2 Entitiy Manger very specific to each .ear file deployment. Instead we are getting only one entity manager - the last one that gets loaded - for entire JVM environment. What can we do to seprate it out. We tries "isolate" of .ear but that doesn't work either. Any example or suggestions will be helpful.