matthias
matthias

Reputation: 2062

Calling multiple EJB methods in JSF managed bean, do each run in same or separate transaction?

I have the following managed bean:

@ManagedBean
@ViewScoped
public class View {
  @EJB
  private Bar bar

  public void foo() {
     bar.do();
     bar.do();
     bar.do();
  }
}

Will this lead to 3 single transactions (one for each bar.do() call) or will this lead to 1 transaction (foo()) ?

Upvotes: 1

Views: 707

Answers (2)

The Bitman
The Bitman

Reputation: 1329

If you want to use just 1 transaction and more then one EJB method call, then 1., use the session facade design pattern. Create a facae bean with CMT (Container Managed Transaction) to call the other beans within its own transaction. 2., Use BMT (Bean Managed Transaction)

Upvotes: 0

Predrag Maric
Predrag Maric

Reputation: 24433

You will have 3 separate transactions, since EJB container starts the transaction on the beginning of the bean method and ends it when the method is finished (this is done automatically for Container Managed Transactions, with Bean Managed Transactions you do this manually).

Upvotes: 2

Related Questions