Transaction question


EJB programming & troubleshooting: Transaction question

  1. Transaction question (1 messages)

    In our application we are mixing entity beans with JDBC. Mostly we use JDBC in read-only mode. But now we want to make update thru JDBC while this is faster. We have to increase or decrease on field for some data. If in our application an error occurs after JDBC call, will be this rolled back or have we to create new user transaction for this JDBC call?
  2. Transaction question[ Go to top ]

    You should be able to incorporate JDBC operations in the same transaction as your entities. Here is what you need to do:

    1) Make the JDBC call (a) from within an EJB or (b) from an object called by an EJB. A typical scenario is a Session EJB calling a Data Access Object (DAO).

    2) Make your JDBC connections using a DataSource retrieved from the server via JNDI.

    3) To signal transaction rollback, you need to have an exception thrown by an EJB. In other words, let any error messages in your JDBC logic pass up to your layer, and either throw an EJBException from the EJB or call ejbContext.setRollbackOnly().