I already have a working object storage service, developed in-house - let's call it a database. Now I would like to use spring-data for CRUD operations on it, so that in the future I can easily switch to some conventional database. The question in: how can I implement yet another spring-data repository backend? Any guides, tutorials?
The class design diagram above indicates how we can create a custom repository in Spring Data JPA. We just need to let EmployeeRepository implement the custom interface and define the implementation for the customized repository.
You might wonder where we put the @Repository annotation. The answer is at EmployeeRepository interface. We just have to provide the implementation of the customizing repository, other parts let Spring Framework complete. This article will not cover how this feature works under the hook.
1. Introduction When modeling a real-world system or process, domain-driven design (DDD) style repositories are a good option. For this very purpose, we can use Spring Data JPA as our data access abstraction layer. If you are new to this concept check out this introductory tutorial to help get you up to speed.
The central piece to look at is the API in the Spring Data Commons module. It effectively provides the foundation for all of the existing store implementations. The support consist of the following aspects:
The best way to get started is by having a look at the MongoDB module for example and mimic the implementation. We're currently working on a developer guide whose work-in-progress version you can find in the Spring Data Commons wiki.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With