DAO Pattern in Spring Boot Application

Jaya Node
Object9
Published in
2 min readMar 30, 2020

DAO Pattern:

This is the pattern which is for interacting with Database to perform CRUD operations in the application. This pattern will make the database operations as a separate layer in application development. This works with in low level of application structure to give high abstraction of database operations.

Let us consider an application where we can get Students details with marks obtained and result displays grade obtained.

To develop this application we need to get data from database table where students information stored along with obtained marks. Here iam not digging into MVC architecture deeply. Iam discussing only data retrieving and calculating obtained grade of a particular student.

One scenario is without DAO pattern:

We can write a java class which includes the logic for connecting with Database and retrieving data from database table. After getting data from table we are writing the logic to calculate grade of a student whose marks obtained from database table. So here you can understand that there are two blocks of data added into the class , one is data base related code and another one is code for calculating grade which includes business logic ( that means the logic for finding grade ).

In this scenario whenever there is changes in logic of grade calculation then the total class needed to be recompiled which will impact the deployment process of the application.

If external client wants to access the data with valid authentication where business logic can be different , we need to allow the client to access the data , so here the question is how data can be transferred to the authorized client?

Following are major disadvantages without DAO pattern:

1) if database code and business logic code added in same class then changes in one can reflect the whole class, which needs recompile , re build and redeploy of the application.

2) It is not easy to share the data between applications or external clients of application.

Second scenario with DAO pattern

DAO pattern has the following three main components

1) DAO interface: which has methods to perform CRUD operations

2) DAO implementation class: This class implements all methods defined in DAO interface

3) Model/Value Class: This is the class which is for holding retrieved database table values

Flow of actions in DAO Pattern based Spring Boot Application

--

--