Session Beans
Session Beans
Session Beans
The Duke's Bank application has three session beans: AccountControllerBean,
CustomerControllerBean
, and TxControllerBean. (Tx stands for a business transaction, such
as transferring funds.) These session beans provide a client's view of the application's business
logic. Hidden from the clients are the server-side routines that implement the business logic,
access databases, manage relationships, and perform error checking.
The AccountControllerBean Session Bean
The business methods of the AccountControllerBean session bean perform tasks that fall into
the following categories: creating and removing entities, managing the account-customer
relationship, and getting the account information.
The following methods create and remove entities:
createAccount
removeAccount
These methods of the AccountControllerBean session bean call the create and remove
methods of the Account entity. The createAccount and removeAccount methods throw
application exceptions to indicate invalid method arguments. The createAccount method
throws an IllegalAccountTypeException if the type argument is neither Checking, Savings,
Credit
, nor Money Market. The createAccount method also looks up the specified customer
exists by invoking the EntityManager.find method. If the result of this verification is null, the
createAccount
method throws a CustomerNotFoundException.
The following methods manage the account-customer relationship:
addCustomerToAccount
removeCustomerFromAccount
The Account and Customer entities have a many-to-many relationship. A bank account can be
jointly held by more than one customer, and a customer can have multiple accounts.
In the Duke's Bank application, the addCustomerToAccount and removeCustomerFromAccount
methods of the AccountControllerBean session bean manage the account-customer
relationship. The addCustomerToAccount method, for example, starts by verifying that the
customer exists. To create the relationship, the addCustomerToAccount method first looks up
the Customer and Account entities using the EntityManager.find method, then it calls the
Account.addCustomer
method to associate the customer with the account.
The following methods get the account information:
getAccountsOfCustomer
getDetails
Enterprise Beans
Chapter 37 · The Duke's Bank Application
1059