Should finder methods be included in JTA transaction context?

Discussions

EJB programming & troubleshooting: Should finder methods be included in JTA transaction context?

  1. Hello,

    I am using bean managed transactions, using JTA. My code requires to access two entity beans, modify the attributes, and then commit all changes. I am using JTA demarcation, looking up JNDI first, and then begining the transaction, modifying the beans, and finally committing. However, I am unsure as to whether the lookup of the entity bean remote interfaces (i.e. the finder method calls) should be within the JTA transaction ut.begin and ut.commit statements or not.

    1) when using declarative transactions, is it normal to give the ejbfinder method a transactional attribute (i.e. one of Required, Mandatory, Never, Supports, RequiresNew, NotSupport)? Which one is normally used?

    2) For bean managed transactions, should the finder methods be part of the JTA transaction or seperate, and why?

    Thanks

    Paddy
  2. It depends on your situation. In particular, does your transaction require that the data your read not be changed during the scope of the transaction.

    Most people advocate a "default" transactional attribute of "Required". I sometimes advocate using "Supported" for read-only operations (including finders) because you can sometimes get improved performance by avoiding the transaction overhead.

    If you are managing the transaction yourself (BMT), you have to decide the requirements of your transaction on your own.