1 Reply Latest reply on Jan 28, 2009 6:47 PM by Binesh Gummadi

    Share seam jar files across applications

    Binesh Gummadi Novice

      Hi,


      I am trying to put together a design for this requirement where the client wants to make a piece of functionality available to all clients(portlets) in jboss portal. Requirement mostly revolves around custom roles. So the idea is to have a jar file in server/default/lib and clients would use this common API to create, update or query roles.


      So the question is how do I do this?


      1. Hibernate archive?
      2. A jar file with seam components and persistence.xml which will use the JNDI name from a datasource deployed in jboss? So clients don't have to deploy the jar file.


      I want all my clients to use the same version of API. Would appreciate any ideas.

        • 1. Re: Share seam jar files across applications
          Binesh Gummadi Novice

          So, I created a separate java project and packaging it as a jar file. Seems to be working fine but I want to understand it little better. I let seam handle my transactions.


          This project has
          a component.xml
          I just have two entries in it.


          <persistence:managed-persistence-context 
                       name="rolesEntityManager"
                          auto-create="true"
                          entity-manager-factory="#{rolesEntityManagerFactory}"/>
          
          <persistence:entity-manager-factory 
                  name="rolesEntityManagerFactory" 
                  persistence-unit-name="roles"/>
          



          I have a datasource file



          <datasources>
            <local-tx-datasource>
              <jndi-name>rolesDS</jndi-name>
              <connection-url>jdbc:mysql://localhost:3306/roles?jdbcCompliantTruncation=false</connection-url>
              <driver-class>com.mysql.jdbc.Driver</driver-class>
              <user-name>user</user-name>
              <password>password</password>
            </local-tx-datasource>
          </datasources>
          
          



          I included this jar file in a webproject. When I invoke methods from this project, I started getting all sorts of transaction errors like cannot enlist in the current transaction. After fiddling around with the team we ended up with a working solution. Which is is to remove datasource file and created a roles-service.xml



          <?xml version="1.0" encoding="UTF-8"?>
          <!DOCTYPE server>
          
          <server>
          <mbean code="com.mchange.v2.c3p0.mbean.C3P0PooledDataSource"
                    name="jboss:service=rolesDataSource">
               
                <attribute name="JndiName">java:rolesDS</attribute>
                <attribute name="DriverClass">org.gjt.mm.mysql.Driver</attribute>
          
                <attribute name="JdbcUrl">jdbc:mysql://localhost:3306/roles</attribute>
                <attribute name="User">user</attribute>
                <attribute name="Password">password</attribute>
          
                 <attribute name="AcquireIncrement">3</attribute>                     
                 <attribute name="IdleConnectionTestPeriod">1800</attribute>            
                 <attribute name="InitialPoolSize">3</attribute>                     
                 <attribute name="MaxIdleTime">0</attribute>                          
                 <attribute name="MaxPoolSize">50</attribute>                         
                 <attribute name="MinPoolSize">10</attribute>                         
                 <attribute name="PreferredTestQuery">SELECT 1</attribute>   
          
                <depends>jboss:service=Naming</depends>
             </mbean>
             
          </server>
          



          We have a theory that local-tx-datasource in datasource file is causing this issue. Since JBoss is managing transaction manager we get these errors. If you look at roles-service.xml it is a C3P0Datasource. We do not see these transaction errors any more.



          So here is my question.




          1. When you have two persistence managers defined in component.xml how are transactions handled? I understand seam starts a transaction before RESTOREVIEW if it is JTA and before APPLY-REQUEST phase if it is RESOURCELOCAL and the whole nine yard. But I am having trouble understanding how transactions work when I have two different databases and how are they tied to JDBC transactions.
          2. How did the above approach solve my problem?


          Would appreciate any links to the documentation referring this scenario.