Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

DAO Implementation & Hibernate

 
Sidharth Pallai
Ranch Hand
Posts: 134
Hibernate Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can anyone make me clear about the advantages of using DAO framework over Hibernate framework.DAO being a Creational Pattern hides the database implementation details from the client but even Hibernate does the same and maintain easy migration from one database to another through change of dialects.I have seen some implementing DAO Pattern along with Hibernate, which i dont get to understand the actual usefullness.I would be glad if anyone make me undertand about the purpose of above implementation.
 
Matt Gaunt
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The DAO framework allows a further layer of abstraction. Say for instance that one day, your boss walks up to your desk and says that hibernate is to be used no longer and you must go ahead and use a different framework.

Now if you have all the hibernate framework code embedded within your logic, you need to go through and pull apart all of that code and refactor it to use a new framework.

With your DAO layer, you can create a new DAO layer alongside the current one, and after you have tested it using your new framework, you should be able to pull out the current DAO layer using hibernate and put in your new DAO layer using your new framework. And you could do this without touching any of your previously heavily tested and optimised logic code.

Regards

Matt Gaunt
 
Sidharth Pallai
Ranch Hand
Posts: 134
Hibernate Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Matt for such beautiful explanation.
I look forward to know more about the DAO implementation,can you advise some link's that would be helpful for me to undertand the appropriate design & flow for DAO Impl'n.
 
Sidharth Pallai
Ranch Hand
Posts: 134
Hibernate Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Matt,
Can you be bit precise of how a DAO framework along with Hibernate would would be of great usefullness, if there's no replacement for Hibernate in future.I mean, am not going to implement any new framework other than the Hibernate itself.
 
Matt Gaunt
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I wouldn't say a DAO layer with Hibernate is of great usefulness. What I would say is that a DAO layer is of great value.

Personally, I wouldn't create an application without the DAO layer as it abstracts any sort of persistence framework out of the logic in your application. The DAO can be altered in any manner, using different frameworks as and when required. You can swap DAO layers in and out of your application.

Let's say for instance you have a database with a Person table. Using IDE wizards, you can create hibernate objects, annotations, mapping files etc. There would be a hibernate Person object. Now as soon as your logic code starts making calls using the hibernate sessions to save and retrieve those Person objects, you have tied your application to Hibernate. What if hibernate ends up being deprecated and becoming fully incorporated into the EJB3 container. It means there would be no further support or maintenance of hibernate. In order to alter your code, you need to go through all of your logic and change all of your hibernate calls.

If you had a DAO layer in between your hibernate objects, and it is the DAO layer using the hibernate sessions, then your logic layer is completely protected from any ORM framework. You can create a completely new DAO layer if you wish, using something other than hibernate. And if you are coding properly, your DAO classes should be implementing interfaces, such that your logic code only knows about interfaces. And if you are incorporating Hibernate with Spring, then it is easier again to alter and inject new DAO classes into your logic code.

Regards

Matt Gaunt
[ June 03, 2008: Message edited by: Matt Gaunt ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic