uCosminexus Application Server, System Setup and Operation Guide
The sample programs using JPA are stored in the following directory:
Cosminexus-installation-directory\CC\examples\jpa\employeeinfo
Following is the overview and execution procedure of the sample:
Following figure shows the configuration of JPA sample program. In this sample program, the program acquires the employee information and updates the data. Employee information cannot be newly registered or deleted from the database table. The program detects the optimistic lock, if databases change during the processing of the find method to flush the method that is executed on clicking the Update button
Figure M-32 Configuration of JPA sample program
The program accesses the servlet by using the Web browser and displays the execution result on the browser. This sample program calls Stateless Session Bean from the servlet and operates the database by using JPA of Bean.
The following table describes the configuration contents of JPA sample program:
Table M-3 Configuration contents of JPA sample program
| Item | Contents |
|---|---|
| Type of Enterprise Bean | Stateless Session Bean |
| Transaction | CMT |
| Entity Manager | Container management |
| Type of transaction | JTA |
| Persistent context | Scope of transaction |
The following figure shows the configuration of sample program entity.
Figure M-33 Configuration of entities
As shown in the figure, the sample program uses unilateral ManyToOne in the relation between entities. Only the Employee entity class is concretized and the Department entity is used as the internal value of Employee entity. The optimistic lock functionality is implemented in both the entities.
Following figure shows the execution example of the sample program
Figure M-34 Execution example of JPA sample program
The following are the operations in this window:
No process is executed even if you click the Find or Update button without entering a value in [ID].
The following procedure describes the method of executing the sample program:
See Appendix M.1(1) Setting the J2EE server.
See Appendix M.1(2) Customizing the J2EE server.
See Appendix M.1(3) Starting the J2EE server.
The resource adapter must be set to connect this sample program to the database. Set a value other than "NoTransaction" in the transaction support level in the Connector property file to enable the usage of JTA transaction. For the method of setting the resource adapter, see Appendix M.1(4) Setting the resource adapter.
Change the following tags of persistence.xml provided in the sample:
Compile the sample programs by using a batch file (compile.bat) provided in the sample. This batch file creates EJB-JAR file (employeeinfo.jar), WAR file (employeeinfo.war), and EAR file (employeeinfo.ear).
Use the batch file (deployApp.bat) provided in the sample to deploy the application. See Appendix M.1(5) Importing, setting and starting the application.
Execute the SQL in the SQL file (createTable_Oracle.sql, createTable_HiRDB.sql) provided in the sample. Execute SQL to remove, and add the JPA_SAMPLE_EMPLOYEE table and JPA_SAMPLE_DEPARTMENT table. The configuration and registration data of each table is as follows:
| Column name | Explanation |
|---|---|
| ID#1 | Employee ID |
| NAME | Employee name |
| DEPARTMENT_ID#2 | Department ID |
| SALARY | Employee salary |
| EMPLOYEE_VERSION | Column to be used by the optimistic lock functionality |
#1 PK (Primary key)
#2 FK (Foreign key)
| ID | NAME | DEPARTMENT_ID | SALARY | EMPLOYEE_VERSION |
|---|---|---|---|---|
| 1 | George | 1 | 100000 | 1 |
| 2 | John | 1 | 200000 | 1 |
| 3 | Thomas | 1 | 300000 | 1 |
| 4 | James | 2 | 400000 | 1 |
| 5 | Andrew | 2 | 500000 | 1 |
| Column name | Explanation |
|---|---|
| DEPARTMENT_ID# | Department ID |
| DEPARTMENT_NAME | Department name |
| DEPARTMENT_VERSION | Column used by the optimistic lock functionality |
#: PK (Primary key)
| DEPARTMENT_ID | DEPARTMENT_NAME | DEPARTMENT_VERSION |
|---|---|---|
| 1 | Sales | 1 |
| 2 | Human resource | 1 |
Start the browser and specify the following string in the URL:
http://Machine-name: Port-number/ContextRoot/EmployeeInfo.html
If the in-process HTTP server is available, the following URL is specified by default:
http://localhost/employee_information/EmployeeInfo.html
See Appendix M.1(6) Stopping and deleting the application
This sample program provides also the O/R mapping file (orm.xml). Since this program uses annotation, it does not use the O/R mapping file. Even if the sample program is compiled by using the batch file provided in the sample; the O/R mapping file is not stored in JAR file.
Note the following when using the O/R mapping file:
%JAR% cvf jar/EmployeeInfo.jar -C DD META-INF/persistence.xml -C classes employeeinfo |
%JAR% cvf jar/EmployeeInfo.jar -C DD META-INF/persistence.xml -C DD META-INF/orm.xml -C classes employeeinfo |
All Rights Reserved. Copyright (C) 2012, 2013, Hitachi, Ltd.