-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: One Hibernate DAO per table
PostPosted: Wed Apr 25, 2007 11:35 pm 
Newbie

Joined: Tue Jan 31, 2006 8:00 am
Posts: 14
Hi All,

I would want to know what is ideal implementation in real world scenarios.

Is it a popular practice to have one Hibernate DAO (entity based) per Hibernate Domain object or we can have a few DAO's (functionality based) catering to multiple Hibernate Domain objects.

When to adopt which approach is what we are looking at the moment.

Do post you comments on the same.


Regards,


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 26, 2007 5:05 am 
Senior
Senior

Joined: Sat Apr 21, 2007 11:01 pm
Posts: 144
A personal favourite of mine at the moment, is to have a data object for all your domain objects which you then extend so you can add any additional functionality. This is handy because it means you can regenerate your hibernate objects from the database when you need to make schema changes without loosing any custom code you might of written for your domain objects.
With regards to the DAO layer -- I choose to have a <TableName>DAO Interface which extends a HibernateDAOMethods<<TableName>> Interface (this has all the standard methods from HibernateDaoSupport), a <TableName>DAOBaseHibernate which extends Spring's HibernateDaoSupport, and then finally a <TableName>DAOHibernate class that extends my <TableName>DAOBaseHibernate and implements my <TableName>DAO Interface.
It sounds complicated but it's actually quite nice. What I means is that you can keep your auto generated DAOBaseHibernate separated from any custom code you write, again handy if you do a regen from your database after schema changes.
I’m using this pattern for my Job that I’ve been working on for the past year and it works really well. I’ve also recently adopted it for a new project I’m working on for my own personal interest.

Hope that helps.


Top
 Profile  
 
 Post subject: DAO/DO per table
PostPosted: Fri Apr 27, 2007 1:33 am 
Newbie

Joined: Tue Jan 31, 2006 8:00 am
Posts: 14
Hi Adamgibbons,

Thanks for your response. That indeed was very helpful.

What I gathered from your response is you are auto-generating Domain objects per table & create pojo's extending these domain objects so any custom code we have in our custom domain objects will not be impacted by changes to the underlying database table structure.

Also you mention auto-generating DAO's that what I have not heard of. Could you ellaborate a bit more on the same.



Regards,


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 27, 2007 6:14 am 
Senior
Senior

Joined: Sat Apr 21, 2007 11:01 pm
Posts: 144
I think you or I have confused Domain Objects / POJOs / DAOs.
When I think of a Domain object it is just a class that extends a Hibernate generated POJO, also could be called Data Object.
DAOs are what I call the Hibernate "Home" obecjts, these are made with the <hbm2dao /> ant task.
They are your data layer that lets you find a Domain Object (POJO) by ID for example or save a new one.
This is just my personal preference and what we use on our project, I'm sure there are lot's of other ways you can do it or other terms you can give things.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.