The following contents can be realized, if you use an application using JPA:
This subsection 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.
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 5-1 Database access model when JPA is not used
This subsection 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:
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.
The following figure shows a data access model when the JPA is used.
Figure 5-2 Database access model when the JPA is used
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:
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 5.2.2 Entity class and 5.2.3 JPA provider.