Java Reference
In-Depth Information
in situations where you're accessing a resource manager that doesn't support transactions.
This would be a resource manager that would throw an exception if a transaction had been
started. Generally, situations where this might occur are few and far between.
Disabling transactions where you're using a resource manager that supports transactions
may have unintended consequences. In the case of a database, the connection might revert
to auto-commit or an exception might be thrown. Even if you're just retrieving data from a
database, that operation is still performed in the context of a transaction. The semantics of
what will happen aren't well defined and will undoubtedly vary. Don't disable transactions
in an attempt to improve performance—they probably aren't the performance bottleneck.
If you were indeed using a resource manager that doesn't support transactions, you'd an-
notate the class as in the following hypothetical code snippet. These annotations will be
discussed in more detail later in the chapter. If a transaction is already started when a meth-
od on this bean is invoked, the transaction will be suspended:
@TransactionManagement(TransactionManagementType.CONTAINER)
@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
public class BidServiceBean implements BidService {
...
}
In summary, EJBs are by their nature transactional. Disable transactions only if you're us-
ing a resource manager that doesn't support them. Next, let's get a sense of how transac-
tions are implemented.
6.1.5. How EJB transactions are implemented
Your primary concern in writing Enterprise applications is with the correct usage of trans-
actions. The heavy lifting of implementing transaction support is provided by cooperation
of the container and resource managers. Ultimately, everything that you do in code trans-
lates into low-level database operations, such as locking and unlocking rows or tables in a
database, beginning a transaction log, committing a transaction by applying log entries, or
rolling back a transaction by abandoning a transaction log. In Enterprise transaction man-
agement, the component that takes care of transactions for a particular resource is called
a resource manager. Remember that a resource isn't just a database system like Oracle or
PostgreSQL. It could also be a message server like IBM MQSeries or an Enterprise inform-
ation system (EIS) like PeopleSoft CRM.
Search WWH ::




Custom Search