I was configuring Criteria API in DBConfiguration file and I have one table named as audit_log
where I am logging the sign-in user with date-time, status and username.
Here is my DBConfiguration file setup
@Configuration
@ComponentScan
@EntityScan("com.package.scan")
@EnableJpaRepositories("com.package.scan")
/*@PropertySource("classpath:db-config.properties")*/
public class DBConfiguration {
public DBConfiguration() {
logger = LogManager.getLogger(DBConfiguration.class.getName());
}
@Bean
public JdbcTemplate jdbcTemplate(DataSource dataSource)
{
return new JdbcTemplate(dataSource);
}
@Bean
public DataSource dataSource() {
logger.info("dataSource() invoked");
DriverManagerDataSource dataSource = new DriverManagerDataSource();
dataSource.setDriverClassName("org.postgresql.Driver");
dataSource.setUrl("jdbc:postgresql://localhost:5432/x2c");
dataSource.setUsername("postgres");
//dataSource.setPassword("P@ssw0rd");
dataSource.setPassword("home");
logger.info("dataSource = " + dataSource);
return dataSource;
}
@Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
final LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean();
em.setDataSource(dataSource());
em.setPackagesToScan(new String[] { "com.mphasis.x2c.services.admin" });
final HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
// vendorAdapter.set
em.setJpaVendorAdapter(vendorAdapter);
em.setJpaProperties(additionalProperties());
return em;
}
@Bean
public PlatformTransactionManager transactionManager() {
final JpaTransactionManager transactionManager = new JpaTransactionManager();
transactionManager.setEntityManagerFactory(entityManagerFactory().getObject());
return transactionManager;
}
@Bean
public PersistenceExceptionTranslationPostProcessor exceptionTranslation() {
return new PersistenceExceptionTranslationPostProcessor();
}
Properties additionalProperties() {
Properties properties = new Properties();
properties.setProperty("hibernate.hbm2ddl.auto", "create-drop");
properties.setProperty(
"hibernate.dialect", "org.hibernate.dialect.MySQL5Dialect");
return properties;
}
}
Now when I use create-drop it drops my audit_log table which I don't have any idea why and how it's doing so and to prevent it how to resolve. Please enlighten me on this thing.
Also if there is any other thing we can use like "update". But most importantly why is it dropping my audit_log table only.