Suppose you are designing today a JavaEE JSF web application. You have a choice on the one hand between making the methods of your CDI beans @Transactional, and on the other hand injecting (session stateless, or singleton) EJBs in the CDI beans, and then the methods of EJBs would be executed under CMT transactions. What would you prefer? Why? Is it just a matter of taste?
Asked
Active
Viewed 3,400 times
1 Answers
3
CDI should be your default programming model and stacking EJB beneath it should be done only if required because it's costly.
So the rule is: don't use EJB if it doesn't bring feature you don't have in CDI.
If you design a new application, start by using CDI managed beans (POJO) with @Transactional and make them EJB only if you need specific EJB features (component pool, async operation, remote call).
@Transactional is defined in JTA spec as an interceptor binding and your JTA implementation provides you the same service thru this interceptor than the CMT for EJB.