Spring Data Interfaces

The following two tabs change content below.
Prasad Kharkar is a java enthusiast and always keen to explore and learn java technologies. He is SCJP,OCPWCD, OCEJPAD and aspires to be java architect.

Latest posts by Prasad Kharkar (see all)

We have seen introduction to spring data in previous article, this will deal with a brief overview of spring data interfaces.

Spring Data Interfaces:

We are actually going to use spring data jpa and  mongodb while actually creating our examples. We are going to see only generic interfaces in this article leaving store specific interfaces for respective parts.

Repository:

Central repository marker interface. Captures the domain type to manage as well as the domain type’s id type. General purpose is to hold type information as well as being able to discover interfaces that extend this one during classpath scanning for easy Spring bean creation.

This is simply a marker interface. Consider we have a Customer entity and you want to create repository

This helps  framework identify this interface as a Repository. and it will try to find Customer as entity.

CrudRepository:

Interface for generic CRUD operations on a repository for a specific type.
CrudRepository extends Repository and adds methods for finding, saving, inserting entities. It acts as abstraction.

PagingAndSortingRepository:

Extension of CrudRepository to provide additional methods to retrieve entities using the pagination and sorting abstraction.
PagingAndSortingRepository extends CrudRepository and adds functionality for sorting and paging results.
These three interfaces are part of spring data commons.jpa and mongodb will also have these and their own specific functionalities which we are going to cover in further articles.
Share Button

1 comment for “Spring Data Interfaces

Leave a Reply

Your email address will not be published. Required fields are marked *