1. We have moved from vBulletin to XenForo and you are viewing the site in the middle of the move. Though the functional aspect of everything is working fine, we are still working on other changes including the new design on Xenforo.
    Dismiss Notice

Transactions in EJB

Discussion in 'Java' started by prashantSum, Nov 11, 2005.

  1. prashantSum

    prashantSum New Member

    hi all,
    I am little bit confused with EJB Transactions.

    What I heard is we cannot control transactions in EJB with Connection.setAutoCommint(false) and Connection.commit() and Connection.rollback();

    the EJB Container Starts a Transaction , if everything goes well the transaction will be commited otherwise in the catch block we have use SessionContext.setRollbackOnly();

    but I am getting different results...

    I have Stateless Session Bean, Transaction is Container in managed in ejb-jar.xml and Transaction attribute required.

    I am inserting two records in the same table and same database with the same connection object and when I am using SessionContext.setRollbackOnly(); in the catch block and when the second insert is throwing an exception... now the transaction is not getting rolled back i.e. the first record is being inserted.

    and when I am controlling it with Connection.setAutocommit(false) and Connection.commit and Connection.rollback() in the catch block it's working fine.
    i.e. when second statement throwing some exception the transaction is getting rolled back and when there is no exception the transaction is getting commited.

    Does Transactions are managed in differently in different Containers.

    I am using OC4J Server.
    Last edited: Nov 15, 2005
  2. sq9today

    sq9today New Member


    I was thinking this the other day but being new to all of this it's still a little confusing

Share This Page