Wednesday, September 19, 2007

[Arch] Has JPA killed the DAO

I've found an interesting post discussing "JPA killed the DAO". The DAO (Data Access Object) pattern is one of the fundamental patterns used in building software systems. This object abstract and encapsulates all access to the data (database, file, xml...) and provides a common interface, used by the business layer.

The new Java Persistence API defines an interface to persist normal Java objects (POJOs) by annotating the objects with persistence meta data. All the "magic" is done by the EntityManager, providing a generic data access functionality. To write DAOs for each business object where simple CRUD operations take place (only for database) is a boring task. However, JPA is only for database. What if you access files, LDAP or other systems? In these cases a DAO makes sense, because the DAO abstracts all sorts of data access (database, file, ldap or whatever "behind" a common interface). Still, JPA is a major enhancement towards database handling.


adam bien said...

Really good summary of my ideas, thanks!,

Markus Demolsky said...

My pleasure! At present I review the first chapters of your book about Java EE 5 Architecture. Good book.

At the beginning of annotations I analyze annotations very critical, because of the mixture of information in your objects. But today I have another point of view of annotations and love to use JPA. However, the usage of annotations in your business objects must be carefully reconceive.