...
The tutorial creates an enterprise application that has an ejb module and a web module. The ejb module uses Account
entity and Person
entity. The Account
entity has accountNumber
, personId
and balance
attributes. The Person
entity has personId
, personName
and address
attributes. The personId
in Account
entity refers to personId
in Person
entity. The AccountBean
injects EntityManagerFactory
from which it creates EntityManager
object. It is a stateful session bean which has Account
entity object, corresponding Person
entity object, EntityManager
object and EntityManagerFactory
object as state fields. The bean has updateAllValues(String address, String personName, double balance)
method that updates Account
and Person
entity attributes. It has also deposit(double amount)
and withdraw(double amount)
methods for withdrawing and depositing the amounts to the account. In all the above mentioned methods, the EntityManager
object joins the active transaction using joinTransaction()
method as the its {[transaction-type
}} is JTA
and bean's transaction is managed by the container. The initialize(integer accountNumber)
initializes the bean with Account
and Person}}
entity objects corresponding to the {{accountNumber
sent as the parameter. Finally, the EntityManager
object is closed in the destroy()
method.
...
1. Start the geronimo server and open the admin console on a browser window with the url
http://localhost:8080/console.
2. Click on the Embedded DB => DB Manager on the Console Navigation portlet.
...
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
insert into PERSONBME values (1, 'Shane Gibson', '#120, Manhattan, NewYork, USAXXXX'); insert into PERSONBME values (2, 'Rameez Raza', '#130, Times Square, NewYork, USAYYYY'); insert into ACCOUNTBME values (10,1,6500); insert into PERSONBME values (11,2,9000); |
...
7. We need to deploy datasource over AccountDB database for JPA. This datasource will be used by JPA to connect to database and perform DML operations. Admin console can be used to deploy a datasource over AccountDB. Click on the services => Database Pools in the Console => Navigation portlet. This will display the list of database pools currently running in the server.
!21jpg!
8. Click on the Using the Geronimo database pool wizard link. This will open up the Database pools portlet as follows. Provide the value for Name of the Database pool as AccountDS and select Derby embedded as below and click on the Next button.
...
1. Open a browser window and hit the URL as http://localhost:8080/BeanManagedJPA-WEB/. This brings upthe screen shot below. Click on the View Account Details link.
...