Spring provides a very useful interface called Repository.

It is very useful. It is defined as follows

public interface CrudRepository<T, ID extends Serializable>
    extends Repository<T, ID> {


    T save(T entity);    //Saves the given entity.


    T findOne(ID primaryKey);  //Returns the entity identified by the given id.

Iterable<T> findAll();  //Returns all entities.

    Long count();   //Returns the number of entities.


    void delete(T entity);  //Deletes the given entity.

boolean exists(ID primaryKey);  //Returns whether an entity with the given id exists.

// … more functionality omitted.