Transactions in Session Bean

Discussions

EJB programming & troubleshooting: Transactions in Session Bean

  1. Transactions in Session Bean (7 messages)

    When we say Transactions in EJB take care of complete transactionality. Let's assume that I wiriting stateless session bean ,
    If I open a connection with database and I insert record in the database table and commits the data.
    After commiting record insertion using database connection, Transaction moves forward for doing other things.
    If LATER Exception occurs and transaction rollbacks , Will the INSERTED record will be rollbacked?.


    Regards
    Anant Patil

    Threaded Messages (7)

  2. Transactions in Session Bean[ Go to top ]

    If you are using EJB, you should never manually commit or rollback data. You must let the EJB server manage your commits and rollbacks. If you try to do your own commits, you will likely get ugly errors. If you want to manually flag a rollback, you should use SessionContext.setRollbackOnly() rather than Connection.rollback().
  3. Mastering EJB[ Go to top ]

    Download a copy of Ed Roman's Mastering EJB.

    He discusses EJB transactions in his book.

    http://www.theserverside.com/books/masteringEJB/index.jsp
  4. It depends, Say suppose your Stateless ejb calls a DAO and which calls a stored procedure(SP) say on DB2 and assume SP is written in Cobol. So when the SP is called there is no control since the call is triggred. If the transcation continues with other things and execption occurs ahead, then may be you cannot rollback the operation of SP.
  5. Hi Venkatesh,

    You have mentioned one possibility where transaction will not rollback insertion , Great.

    But in Session Bean(may be using DAO) If we are making JDBC connection with any RDBMS using DataSource provided by Appserver. Will XA Data source automatically talk to EJB transactions in Rollback case, Even if the program have commited the insertion.

    Thanks and reagrds
    Anant Patil
  6. A stored procedure written in COBOL has no way to notify the caller if an error occurs? If a SSB calls a DAO, which calls the database to invoke a stored proc, your application will know if anything goes wrong with the store procedure since the database is required to throw an exception if it cannot successfully commit the procedure. I don't think the language with which the procedure was written matters, but if this is the case with COBOL, hell, I would never use it.

    Raffi
  7. All the stored procedures return some sort of return code, which you can use to figure out weather its operation was successful or not, even it does happen in COBOL.

    Well I guess we were discussing here the situation when the SP is done and transcation gives exception ahead due to someother reason. So during that time you cannot rollback your transcation, Since SP has already done its job in legacy environment.
  8. Transaction in SSB[ Go to top ]

    After inserting and commiting record will be commited in database.
    Once the exception occurs through SSB/DAO the transaction willl be definetly rolled back.