Instead of having DAO for each entity, calling Generic DAO simplify the program. (Source Code)
package com.ns.spring.dao.template; import com.ns.spring.dao.GenHbDao; import com.ns.spring.model.MDSE; public interface MdseDao extends GenHbDao<MDSE, String> { }
package com.ns.spring.dao.template.impl; import org.springframework.stereotype.Repository; import com.ns.spring.dao.GenHbDaoImpl; import com.ns.spring.dao.template.MdseDao; import com.ns.spring.model.MDSE; @Repository public class MdseDaoImpl extends GenHbDaoImpl<MDSE, String> implements MdseDao { }
Empty DAO interface, and it’s implementation
package com.ns.spring.service.template; import com.ns.spring.model.MDSE; import com.ns.spring.service.GenHbService; public interface MdseService extends GenHbService<MDSE, String> { }
package com.ns.spring.service.template.impl; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.stereotype.Service; import com.ns.spring.dao.GenHbDao; import com.ns.spring.dao.template.MdseDao; import com.ns.spring.model.MDSE; import com.ns.spring.service.GenHbServiceImpl; import com.ns.spring.service.template.MdseService; @Service("mdseService") public class MdseServiceImpl extends GenHbServiceImpl<MDSE, String> implements MdseService { private MdseDao dao; public MdseServiceImpl() { } @Autowired public MdseServiceImpl(@Qualifier("mdseDaoImpl") GenHbDao<MDSE, String> genericDao) { super(genericDao); this.dao = (MdseDao) genericDao; } }
Empty DAO service interface, and it’s implementation calling super class. It can use the method defined in Generic DAO