Spring Data Flashcards
What is JPA?
Java persistence API
- a list of interfaces meant for the mapping/managing of relational data with java objects
- describes which Java objects to persists and how to persist them
- requires a specific implementation to be used, e.g. Hibernate
- Spring Data JPA in practice: @Entity, @Table, @Id, @GeneratedValue, @Column
What is Spring ORM and Spring Data?
Spring ORM = Spring Object Relational Mapping
- it is a framework built upon Hibernate, which is then built upon by Spring Data JPA
Spring Data = family of Spring modules dealing with data persistence
- includes modules such as Spring Data JPA, Spring Data MongoDB, and Spring Data Redis
What interfaces are available in Spring Data JPA?
- JpaRepository
- extends PagingAndSortingRepository
- extends CrudRepository
- extends Repository
What is @Query used for?
Used to define custom behavior (i.e. SQL code) that may not be provided by Spring
@Query(“SELECT * FROM users SORT BY id ASC;”)
public List getUsersSorted();
Describe some naming conventions for Spring Data repository methods (think CRUD operations)
Operations
- Retrieval: find
- Creation/Update: save
- Delete: delete
Queries
- deal with collections: All
- filter by criteria: By
Examples
- saveAll(), findByName(), deleteById()