Previous Next JavaScript must be enabled to correctly display this content

## Defining a Repository

Learn about Oracle NoSQL Database SDK for Spring Data's `NosqlRepository` interface, which includes methods to save, delete, update individual entities and also findAll, deleteAll on sets of entities.

The entity class that is used for persistence is discoverable by the Spring Data Framework either via annotation or inheritance. The `NosqlRepository` interface enables you to inherit and create an interface for each entity that will use the Oracle NoSQL Database for persistence.

The `NosqlRepository` interface extends Spring's `PagingAndSortingRepository` interface that provides many methods that define queries.

In addition to those methods that are provided by the `NosqlRepository` interface, you can add methods to your repository interface to define derived queries. These interface methods follow a specific naming pattern for Spring derived queries (for more information derived queries, see Query Creation) intercepted by the Spring Data Framework. The Spring Data Framework will use this naming pattern to generate an expression tree, passing this tree to the Oracle NoSQL Database SDK for Spring Data, where this expression tree is converted into an Oracle NoSQL Database query, which is compiled and then executed. These Oracle NoSQL Database queries are executed when you call the repository's respective methods.

If you want to create your derived queries, this must be performed by extending the `NosqlRepository` interface and adding your own Java method signatures that conform to the naming patterns as discussed in the derived queries section.

The following is an example of a code that implements the `NosqlRepository` interface. You must provide the bounded type parameters: the entity type and the data type of the `ID` field. This interface implements a derived query `findByLastName` and returns an iterable instance of the `Student` class.

    import com.oracle.nosql.spring.data.repository.NosqlRepository;

    /*The Student is the entity class, and Long is the data type of the
      primary key in the Student class. This interface implements a derived query
      findByLastName and returns an iterable instance of the Student class.*/
    public interface StudentRepository extends NosqlRepository<Student, Long> {

        /*The Student is searched by lastname and
          an iterable instance of the Student class is returned.*/
        Iterable<Student> findByLastName(String lastname);
    }