8
votes

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.

1

1 Answers

13
votes

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.