Java 如何确保Spring数据JPA不会执行DDL(没有Spring引导)?

Java 如何确保Spring数据JPA不会执行DDL(没有Spring引导)?,java,mysql,spring,hibernate,spring-data-jpa,Java,Mysql,Spring,Hibernate,Spring Data Jpa,我有以下数据库配置 @Configuration @EnableJpaRepositories("com.mycompany.databaseutilities.repo") @ImportResource("classpath:data_source.xml") public class DataConfig { @Autowired DataSource dataSource; @Bean public LocalContainerEntityManagerFac

我有以下数据库配置

@Configuration
@EnableJpaRepositories("com.mycompany.databaseutilities.repo")
@ImportResource("classpath:data_source.xml")
public class DataConfig {

   @Autowired
   DataSource dataSource;

   @Bean
   public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
      LocalContainerEntityManagerFactoryBean ans =
         new LocalContainerEntityManagerFactoryBean();
      ans.setDataSource(dataSource);
      ans.setJpaVendorAdapter(jpaVendorAdapter());
      ans.setPackagesToScan("com.mycompany.databaseutilities.model");
      return ans;
   }

   @Bean
   public JpaVendorAdapter jpaVendorAdapter() {
      HibernateJpaVendorAdapter ans = new HibernateJpaVendorAdapter();
      ans.setShowSql(false);
      ans.setGenerateDdl(false); // is this sufficient?
      ans.setDatabase(Database.MYSQL);
      return ans;
   }

   @Bean
   public PlatformTransactionManager transactionManager() {
      JpaTransactionManager ans = new JpaTransactionManager();
      ans.setEntityManagerFactory(entityManagerFactory().getObject());

      return ans;
   }
}
com.mycompany.databaseutilities.model
包含类,由
@Entity


我能确定它不会执行任何DDL语句吗?我不希望损坏现有数据库。

您可以在spring boot
application.properties
application.yaml
文件中指定
spring.jpa.hibernate.ddl auto
属性

您还可以在创建
LocalContainerEntityManagerFactoryBean
时通过提供以下属性来指定:

final Properties jpaProperties = new Properties();
jpaProperties.put( AvailableSettings.HBM2DDL_AUTO, "false" );

entityManagerFactoryBean.setJpaProperties( jpaProperties );

spring.jpa.hibernate.ddl auto=update不向应用程序的db用户/架构授予ddl权限,您就安全了。@KumaresanPerumal在哪里写这个?我没有任何配置文件。@DraganBozanovic我需要应用程序能够进行DDL,我只是不需要它自己去做。