I often encounter the situation when I need to retrieve and store data from/to existing database tables. Writing DAOs and value objects for this is rather tedious and I came up with an idea about only having to write value objects, which I then annotate with some annotations that describes the mapping to table and column in the database.
Then there is some kind of persistence manager, no DAOs, that accesses the database reading and writing data.
I cannot possibly be the first one to have come to think of this idea, so now I am looking for some existing framework that can help me do this.
So, anyone got any names for me?
Many thanks in advance!
You are talking about persistence technologies . JPA introduced with EJB 3 does this and you can plug in the desired persistence provider. And there are some providers Hibernate,iBatis (among the mostly used) etc.. you might want to look at.
Im no friend of writing one DAO for multiple entities. Requirements are changing during development. You have to write more and more DAO-methods so you end up with one bloated DAO class you have to refactor.
What Im doing is writing one DAO per entity class with a generic super class to implement CRUD methods which is the same to all entities.
Thanks a lot guys!
Yes, I have seen DAOs that heavily uses generics and indeed it helps some to cut down on the amount of code.
I often face a lot of requirement changes regarding database schemas, so I prefer multiple DAOs.
Well, I definitely have some material to investigate!
You will also find that there are a slew of DAO generators out there, many of which will either read the database and generate DAOs for you, or read your Java code and generate the database for you. JavaRanch has it's own code generator based on DB structures: Jenny (see also the Jenny FAQ) - very lightweight, but you will have to determine for yourself whether it is a good fit or not. There are plenty of other tools out there as well that will create DAOs for you - one I have used extensively is XDoclet - very good at working from any way of viewing the data and generating the "other" code for you.