Hitachi

uCosminexus Application Server Compatibility Guide


8.2.1 Advantages of applications using JPA

The following contents can be realized, if you use an application using JPA:

This section compares the data access models when the JPA is not used and when the JPA is used, and describe the advantages of applications using the JPA.

Organization of this subsection

(1) Data access model when the JPA is not used

To access a database from a J2EE application when the JPA is not used, you can use the data access model shown in the following figure to create an application.

Figure 8‒1: Database access model when JPA is not used

[Figure]

This section describes the above figure.

With the data access model shown in the figure, you create a class called DAO corresponding to the table to hide the SQL statement from the business logic. With the DAO class, you create a process to issue an SQL statement using the JDBC interface. The flow of processing shown in the figure is as follows:

  1. With an EJB where the business logic is coded, DAO is used to read the data from a database.

  2. The acquired data is stored in an object called DTO.

  3. The DTO object returns to the Web component. With the Web component, the data acquired from the database is output to a Web page.

With such a data access model, if the data model of the database becomes more complex, the number of DAO, SQL, and DTO classes that must be created also increases. The creation of DAO, SQL, and DTO involves monotonous manual work, so this decreases the productivity of an application development.

(2) Data access model when the JPA is used

The following figure shows a data access model when the JPA is used.

Figure 8‒2: Database access model when the JPA is used

[Figure]

When the JPA is used, you create a class corresponding to the lines in the database table. This class is called an entity class. With an EJB where the business logic is coded, you can code the processing as if the object of this entity class is directly stored in the database.

The description of the figure is as follows:

  1. The JPA engine called the JPA provider issues an SQL statement for the database. Also, the JPA provider automatically synchronizes the status of the entity object and the database table.

  2. The entity object can pass the obtained data to the Web component as is.

If you use the JPA, you need not create DTO. Furthermore, the entity class can also be automatically generated from the database table schema by using a development tool such as Eclipse. Because you do not need to create the DAO, SQL, and DTO classes that were the reason of decreased productivity in the past data access models, you can further improve the productivity of the applications.

For details about the entity classes and the JPA providers, see 8.2.2 Entity class and 8.2.3 JPA provider.