Running the JPA entity test
Now we can run the test:
| Make sure that the ITSOBANKderby connection is disconnected (with Embedded Derby you can only have one active connection to a database). You can verify this in the JPA perspective, Data Source Explorer. If the connection is active, right-click the connection and select Disconnect.
|
| Right-click the EntityTester class and select Run | s Æ Java Application.
|
| Select Run Æ Run Configurations. You can find the EntityTester configuration under Java Application.
|
| Select the Arguments tab.
|
| For Program arguments, type 333-33-3333 (we want to work with that employee).
|
| For VM arguments, type (use the installation directory):
|
-javaagent:c:/IBM/SDP75/runtimes/base_v7/plugins/com.ibm.ws.jpa.jar
Note: OpenJPA includes a Java agent for automatically enhancing persistent classes as they are loaded into the JVM. Java agents are classes that are invoked prior to your application's main method. OpenJPA's agent uses JVM hooks to intercept all class loading to enhance classes that have persistence metadata before the JVM loads them.
|
Figure 12-13 Run configuration arguments
| Click Apply, the click Run. The Console displays the output (Example | 2-11).
|
Example 12-11 Sample output of entity tester
Entity Testing
Creating EntityManager
RAD75JPA EntityManager successfully created
All customers:
Aug 11, 2008 3:54:30 PM null null
SEVERE: javaAccessorNotSet
111-11-1111 Mr Henry Cui
222-22-2222 Ms Pinar Ugurlu
333-33-3333 Mr Marco Rohr
444-44-4444 Mr Xxxxx Yyyyyyy
555-55-5555 Mr Aaaa Bbbbb
666-66-6666 Mr Patrick Gan
777-77-7777 Mr Celso Gonzales
888-88-8888 Mr Cccccc Ddddddd
999-99-9999 Mr Eeeeeee Fffffffff
000-00-0000 Mr Ueli Wahli
Customers by partial name: a
666-66-6666 Mr Patrick Gan
777-77-7777 Mr Celso Gonzales
000-00-0000 Mr Ueli Wahli
Retrieve one customer: 333-33-3333
333-33-3333 Mr Marco Rohr
Customer has 3 accounts
Account: 003-999000777 balance 9926.52
Account: 003-999000999 balance 21.56
Account: 003-999000888 balance 568.79
Retrieve customer accounts sorted using named query:
Account: 003-999000777 balance 9876.52
Account: 003-999000888 balance 568.79
Account: 003-999000999 balance 21.56
Perform transactions on one account:
Account: 003-999000777 balance 9876.52
Tx created: 003-999000777 Credit 100 2008-08-11 16:01:46.14 id
5c6e691c-f107-4902-8be8-93e4230fcba6
Tx created: 003-999000777 Debit 50 2008-08-11 16:01:46.14 id
25a93a1a-7ef5-4a23-a925-6f7c638cddd3
Transaction failed: Not enough funds for DEBIT of 10076.52
Account: 003-999000777 balance 9926.52
Account has 2 transactions
Transaction: Credit 100 2008-08-11 16:01:46.14 id
5c6e691c-f107-4902-8be8-93e4230fcba6
Transaction: Debit 50 2008-08-11 16:01:46.14 id
25a93a1a-7ef5-4a23-a925-6f7c638cddd3
| Repeat the test by selecting Run Æ Run History Æ Entity Tester. This time four transactions are listed for the account.
|