August 2018
Intermediate to advanced
314 pages
8h 9m
English
In order to reuse a lot of code and promote best practices to implement DAO, we will create an abstract DAO, called AbstractDao, which is the superclass of all DAOs, that has methods with the generic logic that can be used by all DAOs:
import javax.persistence.EntityManager;import javax.persistence.PersistenceContext;import javax.persistence.TypedQuery;import java.lang.reflect.ParameterizedType;import java.util.List;import java.util.Map;import java.util.Optional;public abstract class AbstractDao <T extends Entity>{ //EntityManager that provide JPA functionalities @PersistenceContext protected EntityManager em; //Get the type of Subclass that implements Entity interface protected Class<T> getType() { ParameterizedType genericType ...
Read now
Unlock full access