Skip to content

Commit b32beaa

Browse files
committed
Improving the documentation.
1 parent 4106cda commit b32beaa

File tree

2 files changed

+22
-47
lines changed

2 files changed

+22
-47
lines changed

src/main/asciidoc/jdbc-custom-conversions.adoc

+21-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
[[jdbc.custom-converters]]
2+
// for backward compatibility only:
3+
[[jdbc.entity-persistence.custom-converters]]
24
== Custom Conversions
35

46
Spring Data JDBC allows registration of custom converters to influence how values are mapped in the database.
@@ -55,12 +57,26 @@ class MyJdbcConfiguration extends AbstractJdbcConfiguration {
5557
5658
// …
5759
58-
@Overwrite
59-
@Bean
60-
public JdbcCustomConversions jdbcCustomConversions() {
61-
return new JdbcCustomConversions(Arrays.asList(new BooleanToStringConverter(), new StringToBooleanConverter()));
62-
}
60+
@Override
61+
protected List<?> userConverters() {
62+
return Arrays.asList(new BooleanToStringConverter(), new StringToBooleanConverter());
63+
}
64+
6365
}
6466
----
6567

68+
NOTE: In previous versions of Spring Data JDBC it was recommended to directly overwrite `AbstractJdbcConfiguration.jdbcCustomConversions()`.
69+
This is no longer necessary or even recommended, since that method assembles conversions intended for all databases, conversions registered by the `Dialect` used and conversions registered by the user.
70+
If you are migrating from an older version of Spring Data JDBC and have `AbstractJdbcConfiguration.jdbcCustomConversions()` overwritten conversions from your `Dialect` will not get registered.
71+
72+
[[jdbc.custom-converters.jdbc-value]]
73+
// for backward compatibility only:
74+
[[jdbc.entity-persistence.custom-converters.jdbc-value]]
75+
=== JdbcValue
76+
77+
Value conversion uses `JdbcValue` to enrich values propagated to JDBC operations with a `java.sql.Types` type.
78+
Register a custom write converter if you need to specify a JDBC-specific type instead of using type derivation.
79+
This converter should convert the value to `JdbcValue` which has a field for the value and for the actual `JDBCType`.
80+
81+
6682
include::{spring-data-commons-docs}/custom-conversions.adoc[leveloffset=+3]

src/main/asciidoc/jdbc.adoc

+1-42
Original file line numberDiff line numberDiff line change
@@ -263,48 +263,7 @@ p1.bestFriend = AggregateReference.to(p2.id);
263263
----
264264
====
265265

266-
[[jdbc.entity-persistence.custom-converters]]
267-
=== Custom converters
268-
269-
Custom converters can be registered, for types that are not supported by default, by inheriting your configuration from `AbstractJdbcConfiguration` and overwriting the method `jdbcCustomConversions()`.
270-
271-
====
272-
[source,java]
273-
----
274-
@Configuration
275-
class DataJdbcConfiguration extends AbstractJdbcConfiguration {
276-
277-
@Override
278-
public JdbcCustomConversions jdbcCustomConversions() {
279-
return new JdbcCustomConversions(Collections.singletonList(TimestampTzToDateConverter.INSTANCE));
280-
}
281-
282-
@ReadingConverter
283-
enum TimestampTzToDateConverter implements Converter<TIMESTAMPTZ, Date> {
284-
285-
INSTANCE;
286-
287-
@Override
288-
public Date convert(TIMESTAMPTZ source) {
289-
//...
290-
}
291-
}
292-
}
293-
----
294-
====
295-
296-
The constructor of `JdbcCustomConversions` accepts a list of `org.springframework.core.convert.converter.Converter`.
297-
298-
Converters should be annotated with `@ReadingConverter` or `@WritingConverter` in order to control their applicability to only reading from or to writing to the database.
299-
300-
`TIMESTAMPTZ` in the example is a database specific data type that needs conversion into something more suitable for a domain model.
301-
302-
[[jdbc.entity-persistence.custom-converters.jdbc-value]]
303-
==== JdbcValue
304-
305-
Value conversion uses `JdbcValue` to enrich values propagated to JDBC operations with a `java.sql.Types` type.
306-
Register a custom write converter if you need to specify a JDBC-specific type instead of using type derivation.
307-
This converter should convert the value to `JdbcValue` which has a field for the value and for the actual `JDBCType`.
266+
* Types for which you registered suitable [[jdbc.custom-converters, custom conversions]].
308267

309268
[[jdbc.entity-persistence.naming-strategy]]
310269
=== `NamingStrategy`

0 commit comments

Comments
 (0)