I am initiating a JTA transaction within a servlet. Subsequently, this servlet calls the method of a stateful session EJB. In this method some SQL statements are executed and an entity bean is looked up and updated. After the return of that method, the servlet commits the JTA transaction. The stateful session EJB as well as the entity EJB are declared as with TRANSACTION REQUIRED and are placed in two different EJB servers. However, after commit, only the changes due to the SQL statements are done in the database. It looks like the entity bean EJB server does not consider the JTA transaction. Any idea?

Gene De Lisa

You say that your business requirements are to start a transaction at the beginning of the session bean method and then to terminate it at the end of the session bean method. Why don't you forget about starting the transaction in the servlet and let CMT in the beans do their thing? Think of the session bean methods as "use-case" methods. If they use entity beans, you'll usually set the methods to REQUIRES_NEW and the entity bean methods to one that lets it be in the session bean context (mandatory, required, supports).

Why is the session bean updating the database? Are you implementing SessionSynchronization too? Usually, for the sake of transaction handling if you're updating you'll use entities. If the session bean is just reading, then using database data is okay (but you'll probably want to also implement SessionSynchronization).