Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

New Spring Data JDK8 Jsr310JpaConverters not working automatically?

I'm trying to use Spring Data JPA 1.8 new jdk date converters.

In my Spring Boot application I've added a config class like:

@Configuration
@ComponentScan(basePackageClasses = LocalContainerEntityManagerFactoryBean.class)
@EnableJpaAuditing
public class DataConfig {
}

This is how org.springframework.data.jpa.convert.threeten.Jsr310JpaConverters suggests how to apply the auto conversion. I also used direct package references like org.springframework.data.jpa.domain.support and org.springframework.data.jpa.convert.threeten.

The problem is the jdk 8 date conversion do not happen resulting in sql exceptions.

However, when I apply the converter manually to in my domain class like:

@Convert(converter = Jsr310JpaConverters.LocalDateConverter.class)
private LocalDate birthdate;

Then the conversion does work.

like image 302
Marcel Overdijk Avatar asked Mar 24 '15 19:03

Marcel Overdijk


1 Answers

Using Spring Boot can simply add Jsr310JpaConverters like below

@EntityScan(basePackageClasses = { Application.class, Jsr310JpaConverters.class })
@SpringBootApplication
class Application { … }

or add org.springframework.data.jpa.convert.threeten to the packages to scan.

like image 50
Christoph Strobl Avatar answered Nov 12 '22 15:11

Christoph Strobl