Discussions

I have two stateless session beans A and B , both of them having Container Managed transaction.
A client initiates one method of A which is calling a method of B in a loop some 100 times, which is doing some insertion of record in Database. This operation takes a lot of time. So if another client tries to view the records in between that operation , he is not able to view the already inserted records because the records will not be committed(after returning from B) until the call from A returns.

How can i view the already created records from another client? how can i get the data be committed after each successful insertion of record? Should i make bean A Bean managed transaction?

I do not think you need to convert the "B" EJB to Bean Managed. (Although, that can work) Change the transactional attribute of the "B" EJB to "requiresNew". This will start a new transaction, everytime B is called.

The downside to this approach is that this process will take longer, because you have 100 commits instead of 1 commit.

If dirty reads are not an issue in your application, then instead of setting the transactional attribute on EJB B's method to RequiresNew, simply change the Transaction Isolation level to READ_UNCOMMITED, provided your database supports this isolation level, I know Oracle does not support it.

TechTarget provides technology professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective purchase decisions and managing their organizations technology projects - with its network of technology-specific websites, events and online magazines.