我正在尝试进行任何DDL jpa本机查询以引发异常。
我为EntityManager使用以下@Bean:
@Bean
@Primary
public LocalContainerEntityManagerFactoryBean ownDbEntityManager() {
LocalContainerEntityManagerFactoryBean em
= new LocalContainerEntityManagerFactoryBean();
em.setDataSource(ownDbDataSource());
HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
em.setJpaVendorAdapter(vendorAdapter);
HashMap<String, Object> properties = new HashMap<>();
properties.put(... a lot of properties...);
properties.put("generate-ddl", false); // Important one
em.setJpaPropertyMap(properties);
return em;
}
我正在通过@PersistenceContext导入此Bean
@PersistenceContext
private EntityManager entityManager;
@Transactional
public void exec() throws Exception {
entityManager.createNativeQuery("CREATE TABLE ... whatever"); // I want this to throw any kind of exception.
}
我不确定我是否正确理解了generate-ddl属性。 我了解它不应该执行任何DDL操作?我错过了什么吗?
现在,它只是创建表。