Skip to content
Ameen Abozaid
Planned lessonJNR-029-L01

Repository interfaces

  • Lesson 1 of 7
  • Junior
On This Lesson 4 topics

This lesson is planned. The outline below lists the topics it will cover. The full lesson has not been published yet.

In this lesson

get a working repository by declaring an interface.

Planned topics

  • Extend JpaRepository<Entity, IdType>; Spring generates the implementation at startup.
  • You get findById, findAll, save, deleteById, count, and paging for free.
  • save inserts a new entity or merges an existing one; for managed entities it is not needed for updates.
  • findById returns an Optional.
  • Repositories belong to the persistence layer; services use them, controllers do not.
Draft outline details

Demonstration

java
public interface ProductRepository extends JpaRepository<Product, Long> {
}

Check your understanding

Who writes the implementation class?

Show answer

Spring Data, generated at runtime.

Practice

Apply this lesson with the module's lab, exercises and quiz.

Lab and exercises Quiz

Marking a lesson complete is optional and you can undo it any time. Your progress stays in this browser.

Continue to next lesson

Type to search levels, phases, modules and lessons.