Files
spring-data-examples/jdbc/basics
Mark Paluch 23dcae3a17 Switch to records.
See #606.
2021-04-30 10:28:59 +02:00
..
2021-04-30 10:28:59 +02:00
2019-11-11 14:40:37 +01:00
2018-05-24 09:42:48 +02:00

== Spring Data JDBC basics

=== SimpleEntityTests

This example demonstrate basic usage of JDBC based repositories.

* The `SimpleEntityTests` demonstrate CRUD operations for an entity without references, just simple properties of various types.

* The `CategoryContext` shows how to configure an application context so that Spring Data JDBC can create repositories.

* The `ApplicationListener` registered in `CategoryContext` demonstrate how to react to events published by Spring Data JDBC and how entities can get manipulated in such event listeners.

=== AggregateTests

This example demonstrates various ways to bend what the standard mapping of Spring Data JDBC can do.

* `AggregateConfiguration.idSetting()` registers an `ApplicationListener` to implement a custom id generation strategy for `LegoSet` and `Manual`.

* `AggregateConfiguration.namingStrategy()` registers a custom `NamingStrategy` in order to map property and class names to database columns and tables.

* The `minimumAge` and `maximumAge` properties show a way to use types which don't have direct mapping to a SQL type, by marking them with `@Transient` and having converted properties for Spring Data JDBC to use.

* The `models` attribute demonstrate mapping of a `Map<simple type, entity>`. It does work out of the box, but in this case the the key of the map should be one attribute of the entity.
This is achieved by providing a custom `NamingStrategy` which maps both to the same database column.

* When the database returns a data type for query which Spring Data JDBC doesn't map out of the box a custom conversion can be registered using a `ConversionCustomizer` as demonstrated in `AggregateContext.conversionCustomizer()`.

* `LegoSetRepository` has methods that utilize `@Query` annotations.

* Note that `Model` is a value class, i.e. it is immutable, and doesn't have an ID.