Milliseconds 입력 방법
mysql or mariadb를 이용하며 milliseconds를 입력하지 못하는현상을 개선하지 못하고 사용하였으나 최근 사용하는 library ( or Framework )셋을 변경하고 개선된 환경을 만들었습니다.
사용된 Frameset
ORM – Hibernate 5.2.12
Connection Pool – HikariCP 2.6.3
Mariadb Connector/J – 2.2.3
Mariadb or MySQL 설정
DATETIME ==DATETIME(3) : support millisecondsDATETIME ->DATETIME(0): fractional seconds roundedDATETIME ->DATETIME(6) : support nano seconds
설정
@Bean
@Primary
public PlatformTransactionManager transactionManager() {
JpaTransactionManager transactionManager
= new JpaTransactionManager();
transactionManager.setEntityManagerFactory(
entityManagerFactory().getObject());
return transactionManager;
}
@Bean
@Primary
public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
LocalContainerEntityManagerFactoryBean em
= new LocalContainerEntityManagerFactoryBean();
em.setDataSource(dataSource());
em.setPackagesToScan(
new String[] { "{entitiy classes ex=> com.entity.Entity1}" });
HibernateJpaVendorAdapter vendorAdapter
= new HibernateJpaVendorAdapter();
em.setJpaVendorAdapter(vendorAdapter);
HashMap<String, Object> properties = new HashMap<>();
properties.put("hibernate.hbm2ddl.auto", "validate" );
properties.put("hibernate.dialect", "org.hibernate.dialect.MariaDB53Dialect" );
properties.put("hibernate.show_sql", "true" );
properties.put("hibernate.implicit_naming_strategy", "org.hibernate.boot.model.naming.ImplicitNamingStrategyJpaCompliantImpl" );
// for spring data compatibility
properties.put("hibernate.physical_naming_strategy", "org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy" );
em.setJpaPropertyMap(properties);
return em;
}
@Primary
@Bean
public DataSource dataSource() {
HikariDataSource ds = new HikariDataSource();
ds.setDataSourceProperties(this.getProperties());
ds.setPoolName("my-pool");
ds.setConnectionTestQuery("select now() from dual");
// DataSource Class Name for MariaDB
ds.setDataSourceClassName( "org.mariadb.jdbc.MariaDbDataSource");
//ds.setIdleTimeout(datasourceProperties.getIdleTimeout());
ds.setMaximumPoolSize( 10 );
ds.setConnectionTimeout(5000);
//ds.setMinimumIdle(minIdle);
ds.setConnectionTestQuery("SELECT 1 FROM DUAL");
return ds;
}
private Properties getProperties()
{
Properties prop = new Properties();
prop.put("serverName", "${HOST IP}");
prop.put("databaseName", "${DATA BASE NAME}");
prop.put("user", "${Account ID}");
prop.put("password", "${Account Password}");
// Mariadb Clinet Do Not User Below
// prop.put("cachePrepStmts", "true");
// prop.put("prepStmtCacheSize", "250");
// prop.put("prepStmtCacheSqlLimit", "2048");
// prop.put("encoding", "UTF-8");
return prop;
}