Does Spring Data JDBC support custom type converters

Evgeni Dimitrov :

I have an entity that has a filed of type java.util.Date (or Timestamp, doesn't matter for the case).

public class StatusReason {
    @Column("SRN_ID")
    private Long id;
    @Column("SRN_CREATOR")
    private String creator;
    @Column("SRN_REASON")
    private String reason;
    @Column("SRN_STATUS")
    private String status;
    @Column("SRN_TIMESTAMP")
    private Date timestamp;
//getters, setters, etc...
}

The database is Oracle and the corresponding column is of type TIMESTAMP(6) WITH TIME ZONE

When I call any of the default findById or findAll methods of the repository I get: ConverterNotFoundException: No converter found capable of converting from type [oracle.sql.TIMESTAMPTZ] to type [java.util.Date].

I can create a custom RowMapper for the type and it will work fine. I was just wondering if it's possible to register a custom converter (in my case from oracle.sql.TIMESTAMPTZ to java.util.Date) so can still benefit from the default mapping and use the converter through the whole app.

Jens Schauder :

You can register custom conversions by inheriting your configuration from JdbcConfiguration and overwriting the method jdbcCustomConversions().

JdbcCustomConversions takes a list of Converter as an argument.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=68235&siteId=1