3 Replies Latest reply on Dec 9, 2008 11:23 AM by thesourpuss

    Multiple jar files with interacting Seam components

      Hi all,


      my initial situation:


      several jar-files, where every file can have entities and ejb as seam components in it. Every jar-file has its own component.xml and persistence.xml.


      Is it possible to access entities of other .jar files, without declaring them in persistence.xml (<class> or <jar-file>) or in more flexible manner (because jar-file Version number changes every release or entities can be deleted)?


      Do I have to declare the entityManager in every component.xml? Or can I reuse (access) it in other jar files?


      thanks in advance,


      tony

        • 1. Re: Multiple jar files with interacting Seam components

          I think it is common here to answer posts by yourself :-) IMO the documentation misses the part, where interaction of different seam modules is described (more than one jar-file). Eg: Where do I have to declare multiple persistenceUnits. Is one EntityManager sufficient? Does every jar-file need one component.xml with an extra EntityManager? How does Transaction behave, if more than one entityManager exists? and so on...


          For my application I answer most of this questions, since I studied the source of seam for more than 2 weeks :-)


          If someone is interested in, write me an email!










          • 2. Re: Multiple jar files with interacting Seam components
            maximall

            Hello, Tony.


            How have you solved your issue?



            Thanks in advance



            Maxim.

            • 3. Re: Multiple jar files with interacting Seam components

              As I already described, I used several jar-files, where every jar-file has its own entityManager defined in components.xml. Be aware of unique names within the whole application.


              Content of every components.xml


              <persistence:managed-persistence-context name="myModuleName.entityManager" 
                                                           auto-create="true" 
                                                           persistence-unit-jndi-name="java:/myModuleNameOraclePersistence" />
              
              <component name="myModule.companyDao" class="com.companyName.its.core.service.dao.GenericDaoJpa" auto-create="true">
                      <property name="type">com.companyName.its.core.service.domain.Company</property>
                      <property name="entityManager">#{myModule.entityManager}</property>
                  </component>




              The persistence.xml, just for the sake of completeness:


              <persistence-unit name="MY_MODULE_ORACLE_PERSISTENCE" transaction-type="JTA">
                      
                      <provider>org.hibernate.ejb.HibernatePersistence</provider>
                      
                      <jta-data-source>java:/DefaultDS</jta-data-source>
                      
                      <properties>
                          <property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect" />
                          <property name="hibernate.connection.driver_class" value="org.hsqldb.jdbcDriver" />
                          <property name="hibernate.connection.url" value="jdbc:hsqldb:." />
                          <property name="hibernate.connection.username" value="sa" />
                          <property name="hibernate.connection.password" value="" />
                          <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.connection.release_mode" value="auto"/>
                          <property name="hibernate.connection.autocommit" value="false" />
                          <property name="hibernate.cache.use_second_level_cache" value="false"/>
                          <property name="hibernate.cache.use_query_cache" value="false"/>
                                      
                          <property name="jboss.entity.manager.factory.jndi.name" value="java:/myModuleOraclePersistence" />
                          <!-- only define manager_lookup_class in JavaEE environment -->
                          <property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.JBossTransactionManagerLookup"/>
                          <!-- don't specify hibernate.transaction.factory_class in RESOURCE_LOCAL. It is defined by transaction-type="RESOURCE_LOCAL" -->
                      </properties>
                  </persistence-unit>



              Every persitence.xml must contain its own definition of persistence-unit. In the above examples every entry 'myModule' must be replaced with name of the jar-module.


              The use of entities in other modules is not possible in a flexible manner. But that saves us from some ugly design issues. It should not be possible to access entities of other modules. It should only be possible to access entities of other modules per DAO in the business logic. So only higher hierarchical layers can access lower hierarchical layers. This means that Business Logic accesses DAO and DAO accesses entities in one module. If one module have to access entites of an other module, it has to use the BL of the other module.


              Transaction management with STM works as expected. One transaction over all entityManagers in every module. So you don't have to be aware of something special here.


              Hope that helps!


              regards, tony