Generic Persistence Tier

Learn to design a reusable persistence tier for elegant data access and less code clutter.

Objective

This chapter will focus on designing the data tier by using a single, generic Data Access Object (DAO) for all JPA entities in the system, which will result in elegant data access, with no unnecessary clutter or verbosity.

Problem

In most of the applications developed in the past, the design of the data layer consists of multiple classes.

However, the application can only use simple CRUD operations on the database Hence the design of the persistence layer forces the system to duplicate the logic across multiple DAO classes.

This violates the DRY(Do Not Repeat Yourself) principle.

Note: There is always one to one mapping between DAO & Entity.

Get hands-on with 1200+ tech skills courses.