New Entity New DAO ????

75 views
Skip to first unread message

scs...@gmail.com

unread,
Mar 21, 2013, 9:13:07 PM3/21/13
to java-gen...@googlegroups.com
I am in the middle of developing a proper generic DAO framework and i am going through few pre implementations.

This implementation is good. My only problem is Do we need to create a extra DAO class when we create a entity. For example lets say you have entity named Country and there will
be  a new DAO called CountryDAO like which is doing same basic operations like findByID, findAll, save, delete....

public interface CountryDAO extends GenericDAO<Country, Long> {

}


Like wise if we implemented 100 entities we are getting 100 empty interfaces and DAO classes Then what is the point of having a GENERIC

David Wolverton

unread,
Mar 21, 2013, 10:51:00 PM3/21/13
to java-gen...@googlegroups.com
A valid question, certainly. I don't know the answer in full. I know that it does seem to be an industry standard to have one DAO class per entity type, but I don't know all the reasons behind that. Maybe they're largely historical. Maybe it's an obsolete pattern, or maybe there are still good reasons for it to be a best practice.

I would think one of the biggest reasons for doing it that way is that it makes it easier to make changes later on. If you find out you need special code in the save function for one entity, you already have a place to put it. You don't have to go searching around for all the places you're calling save with this particular entity type. But that may well not be a good enough reason in every case to go through the trouble of having all those DAOs.

This framework does have a "GeneralDAO" as well that does more of what you're talking about. You can have look at that.

Regards,

David W.


--
You received this message because you are subscribed to the Google Groups "java-generic-dao" group.
To unsubscribe from this group and stop receiving emails from it, send an email to java-generic-d...@googlegroups.com.
To post to this group, send email to java-gen...@googlegroups.com.
Visit this group at http://groups.google.com/group/java-generic-dao?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Tercio F. Gaudencio Filho

unread,
Mar 22, 2013, 9:32:50 AM3/22/13
to java-gen...@googlegroups.com
Just some informations about my setup.

I use GenericDAO in a project with more than 200 objects. I have 0 DAO classes.

I use the implementation GeneralDAOImpl. With that class I do all my work in hibernate classes. You don't need to create a DAO for every object. 

Basically I do:

final GeneralDAOImpl dao = new GeneralDAOImpl();
dao.setEntityManager(entityManager);
dao.setSearchProcessor(searchProcessor);
List<Country> countries = dao.search(new Search(Country.class).addFilterEqual("code", "US"));

Regards,


Att.

Tercio Gaudencio Filho
Reply all
Reply to author
Forward
0 new messages