Creating a common repository with Spring Data JPA

How to define common processing for all Repository

Implementation method

Just copy and paste the official document

Common Repository implementation

MyRepositoryImpl.java


class MyRepositoryImpl<T, ID extends Serializable> extends SimpleJpaRepository<T, ID> {

Common Repository settings

JavaConfig.java


@Configuration
@EnableJpaRepositories(repositoryBaseClass = MyRepositoryImpl.class)
class ApplicationConfiguration { … }

or

config.xml


<repositories base-package="com.acme.repository" base-class="….MyRepositoryImpl" />

reference

Official documentation https://docs.spring.io/spring-data/jpa/docs/current/reference/html/#repositories.customize-base-repository

terasoluna documentation http://terasolunaorg.github.io/guideline/5.3.1.RELEASE/ja/ArchitectureInDetail/DataAccessDetail/DataAccessJpa.html#custommethod-all-label

If you want to define two or more base-classes

config.xml


<repositories base-package="com.acme.repository1" base-class="….MyRepository1Impl" />
<repositories base-package="com.acme.repository2" base-class="….MyRepository2Impl" />

https://stackoverflow.com/questions/15008809/multiple-jparepositories-in-xml-config-how-to-configure-with-enablejpareposit

Recommended Posts

Creating a common repository with Spring Data JPA
A memorandum when trying Spring Data JPA with STS
OR search with Spring Data Jpa Specification
Spring Data JPA: Write a query in Pure SQL in @Query of Repository
Creating REST APIs with Spring JPA Data with REST and Lombok incredibly easy.
Creating a local repository
Sort by Spring Data JPA (with compound key sort)
I tried to get started with Spring Data JPA
Spring with Kotorin --8 Repository layer
[spring] Let's use Spring Data JPA
Spring Boot Introductory Guide I tried [Accessing Data with JPA]
[How to install Spring Data Jpa]
[Rails] Creating a new project with rails new
Spring Data JPA SQL log output
Dynamically generate queries with Spring Data JPA (multi-word search) (paging support)
See the behavior of entity update with Spring Boot + Spring Data JPA
Spring with Kotorin --2 RestController and Data Class
Create a simple on-demand batch with Spring Batch
Exists using Specification in Spring Data JPA
Implementation method for multi-data source with Spring boot (Mybatis and Spring Data JPA)
Jackson is unable to JSON serialize hibernateLazyInitializer in Spring Data JPA with error
A story about creating a library that operates next-generation sequencer data with Ruby ruby-htslib
From creating a Spring Boot project to running an application with VS Code
Create a website with Spring Boot + Gradle (jdk1.8.x)
Until data acquisition with Spring Boot + MyBatis + PostgreSQL
Create a simple search app with Spring Boot
Creating a browser automation tool with Ruby + Selenium
Spring Data JPA save select-insert is only insert
Spring Data JPA Entity cross-reference and its notes
Spring with Kotorin --8 Repository layer --Supplement: H2 Database
(Ruby on Rails6) Creating data in a table
Create a web api server with spring boot
Build a WEB system with Spring + Doma + H2DB
Spring Boot + Spring Data JPA About multiple table joins
Create a Spring Boot development environment with docker
Creating a test case
[Rails] Creating a new project with rails new
Creating a timer app with a muddy
Creating a browser automation tool with Ruby + Selenium
I built a Code Pipeline with AWS CDK.
Make System.out a Mock with Spock Test Framework
Creating a common repository with Spring Data JPA
Build a WEB system with Spring + Doma + H2DB + Thymeleaf
Compatibility of Spring JDBC and MyBatis with Spring Data JDBC (provisional)
MySQL JSON type Value search with SpringBoot + Spring JPA
[Spring] Read a message from a YAML file with MessageSource
Creating a Cee-lo game with Ruby 4th Creating a game progress process
[JUnit 5 compatible] Write a test using JUnit 5 with Spring boot 2.2, 2.3
Implement a simple Rest API with Spring Security with Spring Boot 2.0
Until the use of Spring Data and JPA Part 2
[JUnit 5] Write a validation test with Spring Boot! [Parameterization test]
Create a simple demo site with Spring Security with Spring Boot 2.1
Until the use of Spring Data and JPA Part 1
Make the where clause variable in Spring Data JPA
I wrote a test with Spring Boot + JUnit 5 now
How to get started with creating a Rails app
Use Coveralls with GitHub Actions in a Ruby repository
Extract all data about a particular user with ActiveRecord
Build a WEB system with Spring + Doma + H2DB Part 2