
Chapter 6: Enterprise JavaBeans Overview
EJB transaction attribute values
Each EJB component has a transaction attribute that determines
how instances of the component participate in transactions. In EAServer,
you set the transaction attribute in the Transaction tab of the
Component Properties dialog box.
When you design an EJB component, you must decide how the
bean will manage transaction demarcation: either programmatically
in the business methods, or whether the transaction demarcation
will be managed by the container based on the value of the transaction
attribute in the deployment descriptor.
A session bean can use either bean-managed transaction demarcation
or with container-managed transaction demarcation; you cannot create
a session bean where some methods use container-managed demarcation
and others use bean-managed demarcation. An entity bean must use
container-managed transaction demarcation.
Table 6-1 lists
the transaction attribute values. Requires, Supports, Requires New,
or Mandatory are the values that specify container-managed transaction demarcation.
You can set the Transaction Attribute for the component and for individual
methods in the home and remote interfaces. Values set at the method level
override the component setting.
Table 6-1: Transaction attribute values
Attribute
|
Description
|
Not Supported
|
(The component-level default.) The EJB
component's methods never execute as part of a transaction. If the
EJB component is activated by a client that has a pending transaction,
the EJB component’s work is performed outside the existing transaction.
Since entity beans are almost always involved in transactions, this
value is not usually used for an entity bean.
|
Supports
|
The EJB component can execute in the
context of an EAServer transaction, but a transaction is not required
to execute the component’s methods. If a method is called
by a base client that has a pending transaction, the method’s
database work occurs in the scope of the client’s transaction.
Otherwise, the EJB component’s database work is done outside
of any transaction.
|
Required
|
The EJB component always executes in
a transaction. Use this option when your EJB component’s
database activity needs to be coordinated with other components,
so that all components participate in the same transaction.
|
Requires New
|
Whenever the EJB component is instantiated,
a new transaction begins.
|
Mandatory
|
EJB component methods must be called
in the context of a pending transaction. If a client calls a method
without an open transaction, the EAServer ORB throws an exception.
|
Never
|
The component’s methods never
execute as part of a transaction, and the component may cannot be
called in the context of a transaction. If a client or another component
calls the component with an outstanding transaction, EAServer throws
an exception.
|
Bean Managed
|
(For EJB session beans only.) The EJB
component can explicitly begin, commit, and roll back new, independent transactions
by using the javax.transaction.UserTransaction interface.
Transactions begun by the component execute independently of the
client’s transaction. If the component has not begun a
transaction, the component’s database work is performed
independently of any EAServer transaction.
|
Default to component
|
(Method-level default) In the Transactions
tab of the Method properties window, choose this option if the method
should inherit the transaction attribute set in the component properties.
|
Copyright © 2003. Sybase Inc. All rights reserved.
|
|
View this book as PDF 