DAO's are dead? DAO's vs. NamedQuery
deanhiller2000 Mar 20, 2010 5:04 PMI have now not used DAO's on the last 3 projects for 2 years now. Instead we add a NamedQuery of findXXByYYY and a static method findXXByYYYY on the same bean that accepts the EntityManager as a parameter.
That has significantly reduced our code base and complexity of the system. The stateful bean pattern is way easier(without DAOs) as you just use the EntityManager and pass it in to the Data access static method on the bean, so complexity is significantly reduced there. In fact, I don't even know how to do a statefull bean with an extended persistence context using DAO!!!! I only can do it without DAO write now(just my lack of knowledge and the fact that it is much more work to figure out something that seems to not have a benefit)
Some may argue slipping in another DAO implementation is now harder. Well, we have about 30 DAO's on our project so slipping it in now is just as hard. In fact, I would almost prefer to slip in a different EntityManager instead for testing(which I have done before) and keep the code as is.
On 3 projects and 2 years, I don't see the DAO buying anything except more work these days. Maybe I am missing something? I have heard some say you will regret it someday when you need to switch to file system or some system
, but when I walk through the switch in both DAO style and non-DAO style, there is just as much coding on both sides to code in that file system(less by my count actually when we did a mock use case)...in fact, I may just implement the EntityManager and code the fileSystem behind that. Of course, reality is you are probably using EntityManager because it is a database and you need transactional support which a filesystem doesn't provide so the likelyhood of a switch is about 0.0001%....a risk I am willing to take to make our code base simple and the team productive.
thoughts? I just don't get why articles are still being written on DAO's and making them generic, etc. etc. I am having such a hard time finding benefit from them.
thoughts?
thanks,
Dean