DAO Implementation

A generic DAO interface

Dao.java

package dao;

import java.util.List;
import entity.AbstractEntity;

public interface Dao<T extends AbstractEntity, I> {
    List<T> findAll();
    T find(I id);
    T save(T newEntry);
    void delete(I id);
}

The JpaSpecificationExecutor interface declares the methods that can be used to invoke database queries that use the JPA Criteria API. This interface has one type parameter T that describes the type of the queried entity.

In other words, if we need to modify our repository interface to support database queries that use the JPA Criteria API, we have to follow these steps:

  • Extend the JpaSpecificationExecutor interface.
  • Set the type of the managed entity.

On top of the JpaSpecificationExecutor there is a PagingAndSortingRepository abstraction that adds additional methods to ease paginated access to entities.

ExpenseDao.java

package dao;

import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.repository.PagingAndSortingRepository;
import entity.Expense;

public interface ExpenseDao extends PagingAndSortingRepository<Expense, Long>, JpaSpecificationExecutor<Expense> {
}

results matching ""

    No results matching ""