Discussions

EJB programming & troubleshooting: Transaction Rollback Issue using Stateless Session Bean (BMP)

  1. Hi
    I have a senario which is as follows .....
    I have a Stateless Session Bean ( Bean Managed )
    There is a Transaction that starts within this bean - transaction.begin()
    A call is made to a CMP to insert some records
    Some validations are made in the BMP, and accoriding to the outcome of the validations I need to either commit or rollback this Transaction. But when I try and rollback this transaction it fails. This is when I am using Weblogic7 SP4 with Oracle817 Drivers.
    When I replace the CMP with a stored procedure, the Rollback still doesnt happen. I'm getting the connection from a TxDataSource.

    Is there something that I'm missing/not doing in the DTD or the Weblogic Connection Pool setup ? ( I have tried autoCommit=false in the connection pool , but it does not work ! )

    DTD ........... Given Below... (ejb-jar.xml)


    <?xml version="1.0"?>
    <!DOCTYPE ejb-jar PUBLIC '-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 1.1//EN' 'http://java.sun.com/j2ee/dtds/ejb-jar_1_1.dtd'>
    <ejb-jar>
        <enterprise-beans>
            <session>
                <description>FundIncome</description>
                <ejb-name>FundIncome</ejb-name>
                <home>com.xyz.FundIncomeHome</home>
                <remote>com.xyz.FundIncome</remote>
                <ejb-class>com.xyz.FundIncomeEJB</ejb-class>
                <session-type>Stateless</session-type>
                <transaction-type>Bean</transaction-type>
            </session>
        </enterprise-beans>
        <assembly-descriptor></assembly-descriptor>
    </ejb-jar>
  2. Check for the transaction-attribute for your CMP. Does it say "Required"?

    KK
  3. Yes the Transaction Attribute iis set to 'Required', further even when I replace the CMP with a Stored Procedure, the Transaction Rollback dosent work!
  4. Just want to know this,
    R u using CMP Entity bean to communicate from the stateless session, isn't it?
    What is the transaction attribute of the stateless session bean?
  5. Its a Bean Managed Stateless Session Bean, hence will not have a txn State.
    Further, I think I solved the problrm.... WL70 set autocommit for its Connection pool to 'true' by default. Though I do not know how to globally set the autocommit to 'false' using the WL console, I set the autocommit to 'false' in my code where I was using the Connection from the pool and this solved the problem.
  6. setting autoComit = false in the connection pool descriptor is not enough. it is also important to check weather the table type created in the database supports transactions.
    e.g MYISAM table type in mysql doesnot support transactions where INNODB table type does.
    So setting auto commit = false for MYISAM has no effect as the database server sets the auto commit flag to true by default for MYISAM table type.