postgresql - Spring JPA Hibernate 使用 create-drop 自动删除表
问题描述
我在DBConfiguration文件中配置Criteria API ,我有一个表,命名为我在其中记录登录用户的日期时间、状态和用户名。audit_log
这是我的 DBConfiguration 文件设置
@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;
}
}
现在,当我使用 create-drop 时,它会删除我的 audit_log 表,我不知道它为什么以及如何这样做,并阻止它如何解决。请赐教这件事。
此外,如果还有其他我们可以使用的东西,例如"update"。但最重要的是为什么它只删除我的 audit_log 表。
解决方案
推荐阅读
- root-framework - 如何在终端中绘制一个 TH1F 而不在 ROOT 中打开 TBrowser?
- typescript - Typescript泛型使用类构造函数,在工厂函数内扩展另一个具有静态属性的类
- django - Django:如何在同一个相关字段上制作多个过滤器?
- mysql - 联合所有查询的Mysql查询优化
- windows - 在powershell中设置对象的多个属性
- swift - 将按钮放在 PlayerLayer - Swift - 以编程方式
- discord - NameError:名称'bot'未定义
- oracle - Sqlplus 没有启动
- flutter - 如何在flutter中从API中选择索引并分别删除它的数据?
- javascript - React Native 中带有弯曲边缘的图像边框