Transactions in EJB

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

  1. prashantSum

    prashantSum New Member

    Joined:
    Oct 24, 2005
    Messages:
    57
    Likes Received:
    0
    Trophy Points:
    0
    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

    Joined:
    Mar 7, 2008
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    hmmm....

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

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice