I am using spring-boot 1.2.2 with hibernate.version: 4.3.6. Initially, for a simple operation, I used @Converter to map the java8 LocalDateTime field to a timestamp.
In my converter class, I used autoApply = true, as shown below.
@Converter(autoApply = true) public class LocalDateTimePersistenceConverter implements AttributeConverter { @Override public java.sql.Timestamp convertToDatabaseColumn(LocalDateTime entityValue) { return Timestamp.valueOf(entityValue); } @Override public LocalDateTime convertToEntityAttribute(java.sql.Timestamp databaseValue) { return databaseValue.toLocalDateTime(); } }
However, I still have to use @Convert for my object. The converter class is part of the scanned packets. Is this something I have to do to get this to work automatically without using @Convert for all the records in the database?
:: Optional ::
Here is my DB configuration
@Bean public LocalContainerEntityManagerFactoryBean entityManagerFactory() { LocalContainerEntityManagerFactoryBean lef = new LocalContainerEntityManagerFactoryBean(); lef.setDataSource(dataSource()); lef.setJpaVendorAdapter(jpaVendorAdapter()); lef.setPackagesToScan("path to domain and Converter class"); lef.afterPropertiesSet(); return lef; } @Bean public JpaTransactionManager transactionManager() { JpaTransactionManager transactionManager = new JpaTransactionManager(); transactionManager.setEntityManagerFactory(entityManagerFactory().getObject()); return transactionManager; } @Bean public JpaVendorAdapter jpaVendorAdapter() { HibernateJpaVendorAdapter adapter = new HibernateJpaVendorAdapter(); adapter.setDatabase(Database.ORACLE); adapter.setShowSql(false); adapter.setGenerateDdl(false); return adapter; }
Varesh
source share