10.
Pains • A lot of code in the persistent framework and DAOs. 1. Create a GenericDAO interface to define generic CRUD. 2. Implement GenericDAO interface to an Abstract GenericDAO. 3. Define DAO interface for each Domain entity (e.g., TodoDao). 4. Implement each DAO interface and extend the Abstract GenericDAO for specific DAO (e.g., HibernateTodoDao) • Still some duplicated Code in concrete DAOs. • JPQL is not type-safe query. • Pagination need to handle yourself, and integrated from MVC to persistent layer. • If hybrid databases (ex, MySQL + MongoDB) are required for the system, it’s not easy to have similar design concept in the architecture.12年5月28日星期⼀一

26.
DDD: The Speciﬁcation Problem: Business rules often do not fit the responsibility of any of the obvious Entities or Value Objects, and their variety and combinations can overwhelm the basic meaning of the domain object. But moving the rules out of the domain layer is even worse, since the domain code no longer expresses the model. Solution: Create explicit predicate-like Value Objects for specialized purposes. A Specification is a predicate that determines if an object does or does not satisfy some criteria. Spring Data JPA Speciﬁcation API public interface Specification<T> { Predicate toPredicate(Root<T> root, CriteriaQuery<?> query, CriteriaBuilder builder); } Then, you can use one Repository method for all kind of queries which deﬁned by Speciﬁcation List<T> readAll(Specification<T> spec);12年5月28日星期⼀一