background image

Java Persistence Entities

<< The TxControllerBean Session | Database Tables >>
<< The TxControllerBean Session | Database Tables >>

Java Persistence Entities

method, like all methods in session beans that use container-managed transaction demarcation,
has an implicit Required transaction attribute. That is, you don't need to explicitly decorate the
method with a @TransactionAttribute annotation.
Java Persistence Entities
For each business entity represented in our simple bank, the Duke's Bank application has a
matching Java Persistence API entity:
Account
Customer
Tx
The purpose of these entities is to provide an object view of these database tables:
bank_account
, bank_customer, and bank_tx. For each column in a table, the corresponding
entity has an instance variable. Because they use the Java Persistence API, the entities contain no
SQL statements that access the tables. The enterprise bean container manages all data in the
underlying data source, including adding, updating, and deleting data from the database tables.
Unlike the session beans, the entities do not validate method parameters. The session beans
check the parameters and throw the application exceptions, such as
CustomerNotInAccountException
and IllegalAccountTypeException. Consequently, if
some other application were to include these entities, its session beans would also have to
validate the method parameters. Validation code was not added to the entity's methods, in
order to keep the business logic separate from the entity data.
Helper Classes
The EJB JAR files include several helper classes that are used by the enterprise beans. The source
code for these classes is in the following directory:
tut-install/javaeetutorial5/examples/dukesbank/dukesbank-ejb/src/java/com/sun/tutorial/
javaee/dukesbank/util/
Table 37­1
briefly describes the helper classes.
TABLE 37­1
Helper Classes for the Application's Enterprise Beans
Class Name
Description
AccountDetails
Encapsulates the state of an Account instance. Returned by the getDetails
method of AccountControllerBean.
Enterprise Beans
Chapter 37 · The Duke's Bank Application
1061