EJB Transaction Management

Discussions

EJB design: EJB Transaction Management

  1. EJB Transaction Management (3 messages)

    This is probably an easy one but here goes. Say I have a bean in a tranaction. From that bean I call a regular vanilla java class that is located in the classpath and resides in the same jvm as the ejb container. From this java class I perform some functioning and eventually receive a connection to the DB from the JNDI tree and call a stored proc that is suppose to create a record in the db. Now suppose that after the call to the DB from the java class but within the same tranaction on the same call stack an exception of some sort occurs. Will new record be in the data base or not?

    To sum up, do all points of access to the database in a J2EE application need to be ejbs?

    Additionally while I'm here I just had another question pop into mind. Again the same ejb running in an transaction writes to a file on the file system. An error occurs after the write, what happens to the file.

    What's a good resource on tranactions with ejb to read?

    Thanks,

    Matt

    Threaded Messages (3)

  2. EJB Transaction Management[ Go to top ]

    As far as my knowledge goes, a transaction context is not propogated to non-ejb objects running in a container. Therefore, if you have to use transactions within ur java classes u have to lookup for a UserTransaction and then proceed along.
    Now, to answer your question since a problem occurred when the database was being updated, it would never be updated, but in a case where the EJB is updating some data and then the java class is doing some further updates, and if the failure occurs when the java class is updating...the data updated by the EJB will be there and not so for the java class. This is because the same transaction context is not being propogated.
    Coming to the points of access to a database, sure u need EJBs when u want to use transactions...but in case u dont need any transaction but want to just do with some selects, a java class can do the job for you.
  3. EJB Transaction Management[ Go to top ]

    do all points of access to the database in a J2EE >application need to be ejbs?

    Not necessary, transaction context is associated with the
    thread.

    >transaction writes to a file on the file system. An error
    File IO is not transactional.
  4. EJB Transaction Management[ Go to top ]

    To sum up, do all points of access to the database in a J2EE application need to be ejbs?


    No, using a J2EE application you can access a database through RSPs or direct JDBC. When invoking a Legacy RSP a messaging protocol such as JMS or MQSeries is very effective.
    rjb