Declarative Transaction Management
One of the primary advantages of Enterprise JavaBeans is that it allows for declarative transaction management. Without this feature, transactions must be controlled using explicit transaction demarcation, which involves the use of explicit APIs such as the Java Transaction Service (JTS). At best, explicit demarcation is difficult if you use the aforementioned APIs, particularly if you are new to transactional systems. In addition, it requires that the transactional code be written within the business logic, which reduces the clarity of the code. We talk more about explicit transaction management and EJB later in this chapter.
With declarative transaction management, the transactional behavior
of EJBs can be controlled using the @javax.ejb.TransactionAttribute
annotation or the EJB deployment descriptor, both of
which can set transaction attributes for individual enterprise bean
methods. This means that the transactional behavior of an EJB can be
changed without changing the EJB’s business logic by simply annotating the
method in a different way or modifying XML. Declarative transaction
management reduces the complexity of transactions for EJB developers and
application developers and makes it easier to create robust transactional
applications. Where no explicit declarative transaction properties have
been defined, EJB will provide a default (which we’ll soon see).
Transaction Scope
Transaction scope is a crucial concept for understanding transactions. ...
Get Enterprise JavaBeans 3.1, 6th Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.