5 Replies Latest reply on Feb 27, 2004 9:16 AM by wtff

    HELP! Can't configure CMT in JBoss 3.2.3

    nerotnt Newbie

      Don't know where to look anymore.
      I have a Session Bean with the following ejb-jar.xml:

      <?xml version="1.0" encoding="UTF-8"?>
      <!DOCTYPE ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN" "http://java.sun.com/dtd/ejb-jar_2_0.dtd">
      
      <ejb-jar >
      
       <description><![CDATA[No Description.]]></description>
       <display-name>Generated by XDoclet</display-name>
      
       <enterprise-beans>
      
       <!-- Session Beans -->
       <session >
       <description><![CDATA[EJB Test]]></description>
      
       <ejb-name>MpBean</ejb-name>
      
       <home>pt.ejb.MpHome</home>
       <remote>pt.ejb.Mp</remote>
       <local-home>pt.ejb.MpLocalHome</local-home>
       <local>pt.ejb.MpLocal</local>
       <ejb-class>pt.ejb.MpBean</ejb-class>
       <session-type>Stateless</session-type>
       <transaction-type>Container</transaction-type>
      
       </session>
      
       <!-- Entity Beans -->
      
       <!-- Message Driven Beans -->
      
       </enterprise-beans>
      
       <!-- Relationships -->
      
       <!-- Assembly Descriptor -->
       <assembly-descriptor >
      
       <!-- finder permissions -->
      
       <!-- transactions -->
       <container-transaction >
       <method >
       <ejb-name>MpBean</ejb-name>
       <method-name>*</method-name>
       </method>
       <trans-attribute>Required</trans-attribute>
       </container-transaction>
      
       <!-- finder transactions -->
       </assembly-descriptor>
      
      </ejb-jar>
      


      My objective is to use CMT.
      The SB gets deployed successfully and when I execute a SB method it gives no error.
      But no changes are made to the DB! That's my problem. Looks to me that no "commit" is being done.
      Is there another file that I need to configure besides ejb-jar.xml to enable CMT?

      Really need help on this. Giving me headaches.

        • 1. Re: HELP! Can't configure CMT in JBoss 3.2.3
          wtff Newbie

          I don't understand how the deployment descriptor you posted relates to your CMP problem.

          If you want to use CMP (container managed persistence) then you have to write an entity bean, not a session bean.
          An entity bean needs to have its ejb-jar.xml descriptor and can have two further jboss descriptors called jboss.xml and jbosscmp-jdbc.xml.
          These file-formats are explained within the docs/dtd/html-svg directory of the jboss distribution.

          If you're problem is that you cannot access a database from within your current session-bean, then it might be due to the fact that you did not declare a jdbc-datasource within the above deployment descriptor.

          • 2. Re: HELP! Can't configure CMT in JBoss 3.2.3
            nerotnt Newbie

             

            "wtff" wrote:
            I don't understand how the deployment descriptor you posted relates to your CMP problem...


            I mean CMT (Container Managed Transaction), not CMP.

            • 3. Re: HELP! Can't configure CMT in JBoss 3.2.3
              wtff Newbie

              ah, ok. my mistake. them abbrevations...

              I'm not an *expert* on CMT, CMP & Jboss, but there is nothing further
              you need to do to use CMT than configuring it within ejb-jar.xml
              You don't have to specify further options in any other descriptor.

              To me, it seems as if your ejb.jar.xml descriptor looks fine. It has the transaction-type set to container and the trans-attribute set to Required.
              That's fine. Now any method is wrapped in a single transaction that commits when the method ends, unless you have called setRollbackOnly() or whatever the name is...

              Hmm, since you're deployment descriptor does not contain a resource-ref section, I wonder what kind of database API you are working with. Maybe the transaction context is not passed on to the DB manager you are using.

              You could try to look at the transaction logs of your database to see whether a rollback occurs. And you could switch on call-logging in jboss to see if the transaction is rolled back inside JBoss.

              However, are you sure that CMT is the cause of your problem?
              Do your database calls succeed if you use BMT instead?
              Your statement that no rollback exception is thrown means that the transaction completed successfully within JBoss.
              Maybe the problem lies elsewhere.

              Concerning CMT, I would recommend to use the standard jdbc Datasource mechanism. I believe, JBoss can pass on the transaction context to those types of resource managers known within the J2EE world.

              can you provide me with more information?
              what kind of persistence mechanism are you using?
              why does your descriptor not contain a resource-ref section?
              Is the DB code directly inside your MpBean or inside another bean that the MpBean calls?

              • 4. Re: HELP! Can't configure CMT in JBoss 3.2.3
                nerotnt Newbie

                 

                "wtff" wrote:
                ah, ok. my mistake. them abbrevations...


                First of all let me thank you for so detailed reply.

                Now, I'm using Hibernate as my persistence layer. I have my business methods in classes.
                I want to have a service layer with Session Beans to execute those business methods and have CMT control my transactions.
                I've deployed Hibernate as a SAR with the following jboss-service.xml:

                <server>
                <mbean code="net.sf.hibernate.jmx.HibernateService" name="jboss.jca:service=ArsolHibernateFactory,
                 name=ArsolHibernateFactory">
                 <depends>jboss.jca:service=RARDeployer</depends>
                 <depends>jboss.jca:service=LocalTxCM,name=arsolDS</depends>
                 <!-- Make it deploy ONLY after DataSource had been started -->
                 <attribute name="MapResources">
                 mapping/ArmazemMistura.hbm.xml,
                 mapping/ArmazemMp.hbm.xml,
                 mapping/ArmazemPa.hbm.xml,
                 mapping/ArmazemPeca.hbm.xml
                 </attribute>
                 <attribute name="JndiName">java:/hibernate/ArsolHibernateFactory</attribute>
                 <attribute name="Datasource">java:/arsolDS</attribute>
                 <attribute name="Dialect">net.sf.hibernate.dialect.PostgreSQLDialect</attribute>
                 <attribute name="TransactionStrategy">net.sf.hibernate.transaction.JTATransactionFactory</attribute>
                 <attribute name="TransactionManagerLookupStrategy">net.sf.hibernate.transaction.JBossTransactionManagerLookup</attribute>
                 <attribute name="UseOuterJoin">false</attribute>
                 <attribute name="ShowSql">false</attribute>
                 <attribute name="UserTransactionName">UserTransaction</attribute>
                </mbean>
                </server>
                


                Here's my datasource:

                <?xml version="1.0" encoding="UTF-8"?>
                
                <datasources>
                 <local-tx-datasource>
                 <jndi-name>arsolDS</jndi-name>
                 <connection-url>jdbc:postgresql://localhost:5432/devdb</connection-url>
                 <driver-class>org.postgresql.Driver</driver-class>
                 <user-name>user</user-name>
                 <password>pwd</password>
                 </local-tx-datasource>
                
                </datasources>
                


                Apparently, everithing gets deployed with no errors.
                The SAR above is working for a trasaction-per-method style. Now I want to use CMT with Session Beans.

                Any ideas please?

                • 5. Re: HELP! Can't configure CMT in JBoss 3.2.3
                  wtff Newbie

                  Hi,

                  I know hibernate but have never used it, so I cannot help you, but since the JBoss Group is pretty much into it, I suppose that you have chances to get help from someone on this forum.

                  What I'd do:
                  - turn on logging in debug mode for the respective JDBCDriver and hibernate packages to see what exactly goes wrong, or alternatively look at the Postgres logs to see whether anythings hits your database system at all.
                  That way you should be able to find out whether or not a rollback appears.