I'm currently working on the project where this discussion came and I wanted to ask others what do they think about this.
The DAO pattern is (according to wikipedia): "In computer software, a data access object (DAO) is an object that provides an abstract interface to some type of database or persistence mechanism, providing some specific operations without exposing details of the database.".
But, using ORM this is clearly an ORM (eg. Hibernate) job. It exactly provides an abstract interface to some (almost any) type of database.
Reviewing few last projects let's look on the DAO layer. First step is always generic hibernate dao with save(), findById(), findAll() methods. This is for me just proxying hibernate session methods.
A step further I see such interfaces like proposed here: Generic DAO pattern in Hibernate, what completely tightly bounds the DAO to hibernate way of doing persistence (merge, criteria query). This DAO wont be usable with other persistence mechanism than Hibernate.
So the final though is a question: for such common DAO design what new brings DAO pattern? If I want to switch database engine, I'm switching it on hibernate level. So, is this really any benefits currently from using DAO patterns in ORM applications?
Let's collect some experience:
- How many times have you seen the DAO class hierarchy tightly bound to Hibernate (or other ORM) and what do you think about benefits from that?
- In how many projects do you changed the persistence mechanism in the way that you got benefits from DAO layer (ie. you needed to implement other DAO layer because your job cannot be done on ORM level by switching db dialect)?
- In how many projects you just developed large DAO structure (interface+class for each domain object) and never used this really (ie. you never changed implementation of base DAO hierarchy)?
- What do you think, then, about applications without DAO layer, just using the abstraction provided by ORM sessions?
Please share with experience.