Spring Data Examples

repository·main·Indexed 26 days ago

https://github.com/spring-projects/spring-data-examples

A collection of examples for Spring Data projects, including Spring Data R2DBC, Cassandra, Couchbase, Elasticsearch, and JPA. It demonstrates features such as reactive data access with Project Reactor and RxJava 1, vector search in Apache Cassandra, Kotlin integration for Cassandra entities, and advanced JPA techniques like @EntityGraph, @Procedure, and multiple datasource configurations.

Tokens
35.6K
Snippets
107
Records
199
Agent score
88%

What's inside spring-data-examples

  1. Overview of Spring Data JPA with Spring Data Envers

    main

    This project demonstrates how to use Spring Data JPA in combination with Spring Data Envers.

    Envers is a Hibernate module that provides an auditing and versioning solution for entity classes, compatible with both Hibernate and JPA. Spring Data Envers integrates this functionality with Spring Data JPA, allowing revision information to be accessed directly through JPA-based repositories.

  2. Overview of Spring Data JDBC with Immutables

    main

    This example demonstrates how to integrate Immutables with Spring Data JDBC. The pattern involves defining an interface or abstract class, which Immutables uses to generate an immutable implementation for application use.

    Key Capabilities:

    • Persisting immutable objects works out of the box.
    • Associating saved objects with generated identifiers works out of the box.

    Requirements for Reading:

    • To support the reading side (mapping database rows to immutable objects), you must redirect the object type being created. Refer to ImmutablesJdbcConfiguration in the project for implementation details.

    Known Limitations:

    • Using @Value.Style(allParameters = true) or @Value.Parameter causes Immutables to generate additional constructors. This can conflict with Spring Data's constructor resolution, as Spring Data may struggle to reliably identify the correct persistence constructor.
  3. Overview of Spring Data Examples

    main
    This repository contains a collection of example projects for various Spring Data modules. These examples are designed to showcase the APIs and demonstrate how to use specific features provided by each module. The examples are organized into subdirectories by module name (e.g., spring-data-cassandra, spring-data-jpa, spring-data-mongodb).
  4. Overview of Spring Data Elasticsearch Reactive Examples

    main
    This project demonstrates how to use ReactiveElasticsearchClient, which is built on top of WebClient. It utilizes request/response objects from the Elasticsearch core project and operates directly on the reactive stack rather than wrapping thread-pool-bound async responses into reactive types. The client integrates with ReactiveElasticsearchOperations and ReactiveElasticsearchRepository.
  5. Overview of Spring Data web support integration with Spring MVC

    main

    This example demonstrates how Spring Data integrates with Spring MVC to simplify web layer operations. It specifically covers two main capabilities:

    1. Automatic Pageable creation: Spring Data can automatically resolve Pageable instances from incoming HTTP request parameters, allowing for seamless pagination in controller methods.
    2. Request payload binding via interfaces: Instead of creating concrete DTO classes, you can use interfaces to bind request payloads. Spring Data provides a Map-backed proxy for these interfaces, enabling you to easily create form-backing objects from request data.
  6. Explore Hibernate Multitenancy with Spring Data JPA examples

    main

    This project provides examples demonstrating how to integrate Hibernate's Multitenant feature with Spring Data JPA. It covers three distinct strategies for tenant data separation:

    1. Partition tables by tenant id: Data is separated within the same tables using a tenant identifier.
    2. Separate schema per tenant: Each tenant has its own schema within the same database.
    3. Separate database per tenant: Each tenant is isolated in its own dedicated database.

    Warning: These examples use a singleton to store the tenant context. For production applications, you must implement a more appropriate way to scope the tenant (e.g., using ThreadLocal or request-scoped components).

  7. Use FluentMongoOperations for MongoDB operations

    main
    Use FluentMongoOperations as a focused, stripped-down alternative to the classic MongoOperations. It provides an immutable, fluent API for finding and manipulating Documents on a domain type base. While MongoOperations extends FluentMongoOperations, you can often use the reduced interface by simply injecting FluentMongoOperations into your service.