Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Transaction management and CDI

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.

like image 995
Kiva Avatar asked Jan 05 '13 14:01

Kiva


People also ask

What is @transactional used for?

The @Transactional annotation is the metadata that specifies the semantics of the transactions on a method. We have two ways to rollback a transaction: declarative and programmatic. In the declarative approach, we annotate the methods with the @Transactional annotation.

What are the types of transaction management?

Programmatic transaction management − This means that you have to manage the transaction with the help of programming. That gives you extreme flexibility, but it is difficult to maintain. Declarative transaction management − This means you separate transaction management from the business code.

What is transaction management in JPA?

The transaction management is one of the most important Java Persistence API aspects if you are using Hibernate or any other JPA provider you should know how valuable transaction management is. The JPA transaction determines when the new, modified or deleted entity is synchronised with a database.

What is transactional management in Java?

TransactionManager: An interface which allows an application server to demarcate and control transactions. UserTransaction: This interface allows an application program to demarcate and control transactions explicitly.


2 Answers

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.

like image 113
LightGuard Avatar answered Sep 23 '22 02:09

LightGuard


Transaction management is a different API so it does not matter weather you use it with CDI or EJB.

like image 31
sumit sharma Avatar answered Sep 23 '22 02:09

sumit sharma