- Notifications
You must be signed in to change notification settings - Fork378
Spring Data Relational. Home of Spring Data JDBC and Spring Data R2DBC.
License
spring-projects/spring-data-relational
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
The primary goal of theSpring Data project is to make it easier to build Spring-powered applications that use new data access technologies such as non-relational databases, map-reduce frameworks, and cloud based data services.
Spring Data Relational, part of the larger Spring Data family, makes it easy to implement repositories for SQL databases.This module deals with enhanced support for JDBC and R2DBC based data access layers.It makes it easier to build Spring powered applications that use data access technologies.
It aims at being conceptually easy.In order to achieve this it does NOT offer caching, lazy loading, write behind or many other features of JPA.This makes Spring Data JDBC and Spring Data R2DBC a simple, limited, opinionated ORM.
Implementation of CRUD methods for Aggregates.
@QueryannotationSupport for transparent auditing (created, last changed)
Events for persistence events
Possibility to integrate custom repository code
JavaConfig based repository configuration through
@EnableJdbcRepositoriesrespective@EnableR2dbcRepositoriesJDBC-only: Integration with MyBatis
This project is governed by theSpring Code of Conduct. By participating, you are expected to uphold this code of conduct. Please report unacceptable behavior tospring-code-of-conduct@pivotal.io.
Here is a quick teaser of an application using Spring Data JDBC Repositories in Java:
@TablepublicclassPerson {@IdprivateLongid;privateStringfirstname;privateStringlastname;// getters and setters}interfacePersonRepositoryextendsCrudRepository<Person,Long> {@Query("SELECT * FROM person WHERE lastname = :lastname")List<Person>findByLastname(Stringlastname);@Query("SELECT * FROM person WHERE firstname LIKE :firstname")List<Person>findByFirstnameLike(Stringfirstname);}@ServiceclassMyService {privatefinalPersonRepositoryrepository;publicMyService(PersonRepositoryrepository) {this.repository =repository; }publicvoiddoWork() {repository.deleteAll();Personperson =newPerson();person.setFirstname("Jens");person.setLastname("Schauder");repository.save(person);List<Person>lastNameResults =repository.findByLastname("Schauder");List<Person>firstNameResults =repository.findByFirstnameLike("Je%"); }}@Configuration@EnableJdbcRepositoriesclassApplicationConfigextendsAbstractJdbcConfiguration {@BeanpublicDataSourcedataSource() {return …; }@BeanpublicNamedParameterJdbcTemplatenamedParameterJdbcTemplate(DataSourcedataSource) {returnnewNamedParameterJdbcTemplate(dataSource); }}
Add the Maven dependency:
<dependency> <groupId>org.springframework.data</groupId> <artifactId>spring-data-jdbc</artifactId> <version>${version}</version></dependency>
If you’d rather like the latest snapshots of the upcoming major version, use our Maven snapshot repository and declare the appropriate dependency version.
<dependency> <groupId>org.springframework.data</groupId> <artifactId>spring-data-jdbc</artifactId> <version>${version}-SNAPSHOT</version></dependency><repository> <id>spring-snapshot</id> <name>Spring Snapshot Repository</name> <url>https://repo.spring.io/snapshot</url></repository>
Here is a quick teaser of an application using Spring Data R2DBC Repositories in Java:
interfacePersonRepositoryextendsReactiveCrudRepository<Person,Long> {@Query("SELECT * FROM person WHERE lastname = :lastname")Flux<Person>findByLastname(Stringlastname);@Query("SELECT * FROM person WHERE firstname LIKE :firstname")Flux<Person>findByFirstnameLike(Stringfirstname);}@ServiceclassMyService {privatefinalPersonRepositoryrepository;publicMyService(PersonRepositoryrepository) {this.repository =repository; }publicFlux<Person>doWork() {Personperson =newPerson();person.setFirstname("Jens");person.setLastname("Schauder");repository.save(person);Mono<Void>deleteAll =repository.deleteAll();Flux<Person>lastNameResults =repository.findByLastname("Schauder");Flux<Person>firstNameResults =repository.findByFirstnameLike("Je%");returndeleteAll.thenMany(lastNameResults.concatWith(firstNameResults)); }}@Configuration@EnableR2dbcRepositoriesclassApplicationConfigextendsAbstractR2dbcConfiguration {@BeanpublicConnectionFactoryconnectionFactory() {returnConnectionFactories.get("r2dbc:<driver>://<host>:<port>/<database>"); }}
Add the Maven dependency:
<dependency> <groupId>org.springframework.data</groupId> <artifactId>spring-data-r2dbc</artifactId> <version>${version}</version></dependency>
If you’d rather like the latest snapshots of the upcoming major version, use our Maven snapshot repository and declare the appropriate dependency version.
<dependency> <groupId>org.springframework.data</groupId> <artifactId>spring-data-r2dbc</artifactId> <version>${version}-SNAPSHOT</version></dependency><repository> <id>spring-libs-snapshot</id> <name>Spring Snapshot Repository</name> <url>https://repo.spring.io/snapshot</url></repository>
Having trouble with Spring Data?We’d love to help!
If you are new to Spring Data JDBC read the following two articles"Introducing Spring Data JDBC" and"Spring Data JDBC, References, and Aggregates".
Check thereference documentation, andJavadocs.
Learn the Spring basics – Spring Data builds on Spring Framework, check thespring.io web-site for a wealth of reference documentation.If you are just starting out with Spring, try one of theguides.
If you are upgrading, check out thechangelog for “new and noteworthy” features.
Ask a question - we monitorstackoverflow.com for questions tagged with
spring-data.
Spring Data uses GitHub as issue tracking system to record bugs and feature requests.If you want to raise an issue, please follow the recommendations below:
Before you log a bug, please search the Spring Data JDBCsissue tracker to see if someone has already reported the problem.
If the issue doesn’t already exist,create a new issue.
Please provide as much information as possible with the issue report, we like to know the version of Spring Data that you are using and JVM version.Please include full stack traces when applicable.
If you need to paste code, or include a stack trace use triple backticks before and after your text.
If possible try to create a test-case or project that replicates the issue.Attach a link to your code or a compressed file containing your code.Use an in-memory database when possible.If you need a different database include the setup usingTestcontainers in your test.
You don’t need to build from source to use Spring Data (binaries inrepo.spring.io), but if you want to try out the latest and greatest, Spring Data can be easily built with themaven wrapper.You also need JDK 17.
$ ./mvnw clean install
If you want to build with the regularmvn command, you will needMaven v3.8.0 or above.
Also seeCONTRIBUTING.adoc if you wish to submit pull requests, and in particular please sign theContributor’s Agreement before your first non-trivial change.
$ ./mvnw clean install
Runs integration test against a single in memory database.
To run integration tests against all supported databases specify the Maven Profileall-dbs.
./mvnw clean install -Pall-dbs
This requires an appropriatecontainer-license-acceptance.txt to be on the classpath, signaling that you accept the license of the databases used.
If you don’t want to accept these licences you may add the Maven Profileignore-missing-license.This will ignore the tests that require an explicit license acceptance.
./mvnw clean install -Pall-dbs,ignore-missing-license
If you want to run an integration tests against a different database you can do so by activating an apropriate Spring Profile.Available are the following Spring Profiles:
db2,h2,hsql (default),mariadb,mssql,mysql,oracle,postgres
There are a number of modules in this project, here is a quick overview:
Spring Data Relational: Common infrastructure abstracting general aspects of relational database access.
Spring Data JDBC: Repository support for JDBC-based datasources.
Spring Data R2DBC: Repository support for R2DBC-based datasources.
Spring Data Examples contains example projects that explain specific features in more detail.
Spring Data Relational is Open Source software released under theApache 2.0 license.
About
Spring Data Relational. Home of Spring Data JDBC and Spring Data R2DBC.
Topics
Resources
License
Code of conduct
Contributing
Security policy
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Uh oh!
There was an error while loading.Please reload this page.