- http://java.dzone.com/articles/jpa-implementation-patterns
Pro:
- unify using of EntityManager method of a team
- disallow certain operation / entity types
- theoretically may switch to another persistence system (but not realistically possible....)
- centralize all queries on a certain entity type
- no direct dependency on JPA
- type-safe
- possible to centralize debugging / profiling etc.
- one place to test database access code
- able to unit test business logic with mock DAO
- separate business logic with data access logic (some argue as con)
Against
- overhead
- cannot really hide JPA or under laying persistence mechanism very well
Competing with
Option 1:
See Ref. 1, Vincent suggested:
- one generic DAO interface : public interface Dao<Key, Entity>
- one abstract base JpaDao implementation : implements common methods, such as persist, etc.
- one sub-interface per entity : public interface OrderDao extends Dao<Integer, Order>
- one specific implementation per entity : public class JpaOrderDao extends JoaDao
- see http://java.dzone.com/articles/jpa-implementation-patterns