EJB Commit() & Rollback() not working


EJB programming & troubleshooting: EJB Commit() & Rollback() not working

  1. EJB Commit() & Rollback() not working (6 messages)

    Hi, We hava a J2EE application in WAS 6.0. We are using EJBs which calls a DAO layer. Oracle 10g is the backend and we use Oracle SPs for any CRUD operation. There is a save operation as part of our application which does multiple insert into multiple tables in different methods. There should be a rollback to happen on any exceptions or errors. We are using Session Beans(stateless) where the transactions are Container Managed and we rollback using setRollbackOnly() method of the Session Context. But we dont see any rollback happenning in case of exceptions, even though the setRollbackOnly() is called. Have anyone fixed this kind of error before? Thanks Suresh
  2. I think it is the way you have handled JDBC connection. If you are calling SP, then I think you may have to look at possibility on setting autocommit as false, on the same connection used for calling SP. It is just a guess.... Thanks, Ishtiak http://interview-questions.weebly.com
  3. The autocommit is set to false in our case. We are creating connection as Connection conn = getConnection(">"); Connection myConn = (java.sql.Connection) WSJdbcUtil .getNativeConnection((WSJdbcConnection) conn); We do this as we are using oracle types oracle.sql.ARRAY and oracle.sql.ArrayDescriptor in our Stored procs. The connection object without type casting (in the second line above) is not supporting ARRAY and ArrayDescriptor.
  4. If you are using jndi look up to get a database connection, check whether you are using XA connection factory.
  5. Check the transaction attribute specified for those methods. Transaction attributes are specified for container managed transactions in ejb-jar.xml. For further information on transaction attributes please check the link below: http://java.sun.com/j2ee/tutorial/1_3-fcs/doc/Transaction3.html
  6. The transaction attribute is set to "Required". We identified that the issue was with the WsJdbcConnection that we use as part of the DAO layer. The DAO classes uses oracle.sql.ARRAY and oracle.sql.ArrayDescriptor to pass arrays to the Oracle SPs. The connection is created as below Connection conn = getConnection(>); OracleConnection myConn = (OracleConnection) WSJdbcUtil.getNativeConnection((WSJdbcConnection) conn); In ejb-jar.xml, the transaction attribute of the method submitCustomer is set to “Required?. Note – The rollback and commit are happening if java.sql.Connection is used. But java.sql.Connection cannot be used as it doesn’t accept oracle.sql.ARRAY and oracle.sql.ArrayDescriptor classes
  7. the problem is caused by the line below: OracleConnection myConn = (OracleConnection) WSJdbcUtil.getNativeConnection((WSJdbcConnection) conn); when you are using a native/physical connection instead of the wrapper connection provided by container, you will loss the transactional capability provided by XA datasource. this is because the wrapper connection knows when to enlist into a global transaction but the physical/native connection never knows this kind of information.