1

i have been using playframework since 2 years. Framework has "JPA on streoids" feature. I loved it very much.

http://www.playframework.org/documentation/1.2.4/5things

This is the sample code:

User connectedUser = User.find("byEmail", connected()).first();
...
connectedUser.delete();
...
connectedUser.save();

This aproach uses lots of helper methods. Some of them are static methods. Every model file extends Model class and voila. You may use find, save, delete, fetch...

Nowadays i use Spring MVC 3.1. I like its MVC usage. But Connectivity system is a little bit complex.

I read lots of articles. Some of them use service layer, dao layer and model layer. Some of them use only dao layer and model layer. Somes are creating DAO interfaces and DAO classes for every single model object and also service classes and service interfaces. And some of them use generic DAO classes.

in fact i am a little bit confused about all this variants.

  • Why are we using DAO layer. A single hibernateUtil class and named queries is not enough for CRUD operations.
  • Why don't we use play framework approach?
  • Why do we use interfaces for every DAO class? Just implementation is not enough?
  • Why do we use unnecessary service layer?
DataNucleus
  • 15,497
  • 3
  • 32
  • 37
Fırat Küçük
  • 5,613
  • 2
  • 50
  • 53

1 Answers1

4

A DAO layer is useful to isolate the data acess code from the business logic code. This is especially useful when you start unit-testing the business logic, because it allows mocking the DAOs. All the applications don't simply have CRUD operations.

Interfaces have the same testability advantages. Read what reasons are there to use interfaces (Java EE or Spring and JPA), where I explain the advantages of having interfaces.

The service layer is the most important layer. It is the one used to demarcate transactions. You could avoid using a DAO layer, especially if you have extremely simple crud-like data access. But a service layer is crucial. You don't want to have three inserts and one update each in their own transaction. See DAO Design Pattern and Servlets for a question where I explain why a service layer is so important.

Community
  • 1
  • 1
JB Nizet
  • 678,734
  • 91
  • 1,224
  • 1,255