8

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
  • 77,657
  • 34
  • 181
  • 348
Evgeni Dimitrov
  • 21,976
  • 33
  • 120
  • 145

1 Answers1

7

You can register custom conversions by inheriting your configuration from JdbcConfiguration (Spring Data JDBC v1.x) or AbstractJdbcConfiguration (v2.x). Then overwrite the method jdbcCustomConversions().

JdbcCustomConversions takes a list of Converter as an argument.

Guy C
  • 6,970
  • 5
  • 30
  • 30
Jens Schauder
  • 77,657
  • 34
  • 181
  • 348