Transaction management and CDI

Kiva picture Kiva · Jan 5, 2013 · Viewed 8.8k times · Source

I would like to develop an application with CDI (I use Spring usually) to discover this technology.

I have read many articles about CDI to learn how it works. I have a simple question about transaction management (for persistence in database for example):

Is it mandatory to use EJB 3.1 to have transaction management or is it possible to have it with CDI only ?

Thanks.

Answer

LightGuard picture LightGuard · Jan 6, 2013

No, you can do it with CDI. You simply need to create an interceptor that starts, commits or rollsback a transaction. It's really not that hard. In Java EE 7 there will be a @Transactional for all managed beans (JSF, CDI, EJB, etc) that will be a CDI interceptor.

EDIT: If you'd like to take a look at some that are already done, Apache DeltaSpike and Seam 3 (no longer being developed) have interceptors to handle transactions.