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.
The Spring Framework's JDBC abstraction framework consists of four different packages, namely core , datasource , object , and support .
Spring JDBC only helps with the connection to the database and with executing queries on this database. Spring Data JPA wants to help you manage your JPA based repositories. It wants to remove boilerplate code, make implementation speed higher and provide help for the performance of your application.
Spring Data JDBC is an object-relational mapping framework for relational databases that aims to avoid most of the complexity of other ORM frameworks. It does that by avoiding features like lazy loading, managed lifecycles of entity objects and caching.
Create a project with a name SpringExample and create a package com. tutorialspoint under the src folder in the created project. Add required Spring libraries using Add External JARs option as explained in the Spring Hello World Example chapter. Add Spring JDBC specific latest libraries mysql-connector-java.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With