Based on the article Don't Repeat DAO , we have used this type of technique for many years. We always struggled with problems with our samples after we realized that we had made a big mistake.
With an ORM tool like Hibernate or JPA, you don't have to look at the DAO and the Service layer separately. You can use the EntityManager from your service classes because you know the transaction life cycle and the logic of your object classes.
Do you save any minute if you call myDao.saveEntity instead of just entityManager.saveEntity ? No. You will have an unnecessary dao class that does nothing, but will be a wrapper around the EntityManager. Don't be afraid to write selections in your service classes using the EntityManager (or sleep session).
One more note: you must define the boundaries of your level of service and not allow programmers to return or wait for Entity classes. UI or WS programmers should not even know about entity classes about DTO-s at all. Entity objects have life cycles that most programmers are unaware of. You will have serious problems if you save the entity object in the session data and try updating it to the database in a few seconds or several hours. Well, you may not do this, but a user interface programmer who knows the parameter types and return types of your service level would only do to save some lines of code.
Balazs Zsoldos Nov 01 '12 at 19:48 2012-11-01 19:48
source share