Chapter 3. Reverse Engineering the Domain Layer with JPA

The domain layer represents the real-world entities that model the heart of your application. At the highest level, the domain layer represents the application's business domain and fully describes the entities, their attributes, and their relationships with one another. At its most basic level, the domain layer is a set of Plain Old Java Objects (POJOs) that define the Java representation of the database tables being mapped onto your application. This mapping is achieved through JPA.

The Java Persistence API (JPA) is one of the most significant advances in the Java EE 5 platform, replacing the complex and cumbersome entity beans with the far simpler POJO-based programming model. JPA provides a standard set of rules for Object Relational Mapping (ORM), which are simple, intuitive, and easy to learn. Database relationships, attributes, and constraints are mapped onto POJOs using JPA annotations.

In this chapter we will do the following:

  • Reverse engineer the 3T database using the NetBeans IDE
  • Explore and define JPA annotations for our domain layer
  • Introduce the Java Persistence Query Language (JPQL)

Understanding the reasons for using JPA

JPA is a productivity tool that allows developers to focus on business rather than write low-level SQL and JDBC codes. It completely eliminates the need to map a Java ResultSet to Java domain objects and greatly reduces the amount of effort required to produce a usable and functional application. A JPA-based application will be easier to maintain, test, and enhance. More importantly, the quality of your application code will significantly increase and the domain entities will become self-documenting.

From personal experience, I estimate the time taken to write a traditional SQL application (without JPA, coding the CRUD SQL statements directly) to be in the order of 10-15 times longer than with the JPA approach. This translates into an enormous saving of time and effort for enterprise applications where cost saving can amount to many man-months of work. During the lifecycle of an application, when maintenance, bug fixes, and enhancements are taken into account, cost savings alone may be the difference between success and failure.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.220.53.93