Spring Data JPA: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
Line 15: Line 15:


{{Internal|Spring_Persistence_Concepts#Overview|Spring Persistence Concepts}}
{{Internal|Spring_Persistence_Concepts#Overview|Spring Persistence Concepts}}
=Spring Boot Support=
To add support for Spring Data JPA to a [[Spring Boot]] project, add the following [[Spring_Boot_Concepts#Spring_Boot_Starter_Dependency|starter dependency]]:
<syntaxhighlight lang='groovy'>
dependencies {
    implementation('org.springframework.boot:spring-boot-starter-data-jpa')
}
</syntaxhighlight>
Spring Data JPA needs a database to work with. This is how to add H2 support:
<syntaxhighlight lang='groovy'>
dependencies {
    runtimeOnly('com.h2database:h2')
}
</syntaxhighlight>


=Spring Data JPA Repository=
=Spring Data JPA Repository=

Revision as of 17:00, 15 October 2018

External

Internal

Overview

Spring Data JPA is a Spring Data project that assists with implementing JPA-based repositories, which persist data in relational databases. The approach involves writing the repository interface, including custom finder methods, and Spring will provide the implementation automatically.

Spring Persistence Concepts

Spring Persistence Concepts

Spring Boot Support

To add support for Spring Data JPA to a Spring Boot project, add the following starter dependency:

dependencies {
    implementation('org.springframework.boot:spring-boot-starter-data-jpa')
}

Spring Data JPA needs a database to work with. This is how to add H2 support:

dependencies {
    runtimeOnly('com.h2database:h2')
}

Spring Data JPA Repository

This is a Spring Data JPA concrete repository implementation that conceals from the application low-level data access details while exposing a domain model-typed API, represented by the example "IngredientRepository" interface.

TODO

TODO

  • How to tell that a JPA repository should use a specific database. How is that configured?
  • @EnableJpaRepositories(basePackages = "com.example.dev.myproject.driver.repo")