如何不更新Hibernate中的DDL模式



我尝试使用Spring Batch和Scheduler运行一个应用程序。我看到DDL模式总是更新,我不想更改我的DDL模式。

我在我的应用程序中尝试此操作。

hibernate.hbm2ddl.auto=validate|none

,但它无法解决我的问题。

这是我的不同文件:

application.properties

spring.datasource.url=jdbc:postgresql://localhost/ussd_service
spring.datasource.username=root
spring.datasource.password=password
spring.datasource.driver-class-name=org.postgresql.Driver
spring.jpa.database-platform=org.hibernate.dialect.PostgreSQLDialect
#Hibernate Configuration:
hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect
hibernate.show_sql=true
#DB initialization
hibernate.hbm2ddl.auto=validate
org.hibernate.tool.hbm2ddl=validate
spring.jpa.hibernate.ddl-auto=validate

和我的班级定义数据源

@Configuration
@EnableBatchProcessing
@EntityScan("com.package.myentity")
@ComponentScan(basePackages   = {"com.package.batch.",
                                 "com.package.repository"})
@PropertySource("classpath:application.properties")
public class BatchSmsJobConfig {
  @Value("${spring.datasource.driver-class-name}")
  private String databaseDriver;
  @Value("${spring.datasource.url}")
  private String databaseUrl;
  @Value("${spring.datasource.username}")
  private String databaseUsername;
  @Value("${spring.datasource.password}")
  private String databasePassword;
  @Bean
  public ItemReader<Souscription> reader() throws Exception {
    java.util.Date now = new java.util.Date();
    java.sql.Date date = new java.sql.Date(now.getTime());
    String jpqlQuery = "select u from Users u";
    JpaPagingItemReader<Souscription> reader = new JpaPagingItemReader<Souscription>();
    reader.setQueryString(jpqlQuery);
    reader.setParameterValues(Collections.<String, Object>singletonMap("date", date));
    reader.setEntityManagerFactory(entityManagerFactory().getObject());
    //reader.setPageSize(3);
    reader.afterPropertiesSet();
    reader.setSaveState(true);
    return reader;
  }
  @Bean
  public SouscriptionItemProcessor processor() {
    System.out.println("Processing!");
    return new SouscriptionItemProcessor();
  }

  @Bean
  public ItemWriter<Sms> writer() {
    System.out.println("Writing info into DB!");
    JpaItemWriter writer = new JpaItemWriter<Sms>();
    writer.setEntityManagerFactory(entityManagerFactory().getObject());
    return writer;
  }
  //@Bean
  //public JobExecutionListener listener() {
  //  return new JobCompletionNotificationListener(jdbcTemplate);
  //}
  @Bean
  public Job sendSMStoSubscribersJob(JobBuilderFactory jobs, Step s1) {
    return jobs.get("import")
        .incrementer(new RunIdIncrementer())
        .flow(s1)
        .end()
        .build();
  }
  @Bean
  public Step step1(StepBuilderFactory stepBuilderFactory, ItemReader<Souscription> reader,
                    ItemWriter<Sms> writer, SouscriptionItemProcessor processor) {
    return stepBuilderFactory.get("step1")
        .<Souscription, Sms>chunk(1)
        .reader(reader)
        .processor(processor)
        .writer(writer)
        .build();
  }
  @Bean
  public DataSource dataSource() {
    DriverManagerDataSource dataSource = new DriverManagerDataSource();
    dataSource.setDriverClassName(databaseDriver);
    dataSource.setUrl(databaseUrl);
    dataSource.setUsername(databaseUsername);
    dataSource.setPassword(databasePassword);
    return dataSource;
  }
  @Bean
  public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
    LocalContainerEntityManagerFactoryBean lef = new LocalContainerEntityManagerFactoryBean();
    lef.setPackagesToScan("com.mobilproafrica.batch.sms");
    lef.setDataSource(dataSource());
    lef.setJpaVendorAdapter(jpaVendorAdapter());
    lef.setJpaProperties(new Properties());
    return lef;
  }
  @Bean
  public JpaVendorAdapter jpaVendorAdapter() {
    HibernateJpaVendorAdapter jpaVendorAdapter = new HibernateJpaVendorAdapter();
    jpaVendorAdapter.setDatabase(Database.POSTGRESQL);
    jpaVendorAdapter.setGenerateDdl(true);
    jpaVendorAdapter.setShowSql(true);
    jpaVendorAdapter.setDatabasePlatform("org.hibernate.dialect.PostgreSQLDialect");
    return jpaVendorAdapter;
  }
}

我在控制台日志中看到:

org.hibernate.tool.hbm2ddl.schemaupdate:hhhhh000388:失败: Alter Table tarif添加约束fk_lub9g2g2gwhub3a7pc7u67u67vp3cr外国 键(forfait_id)参考forfait

有人可以帮我这个错误吗?

set

spring.jpa.hibernate.ddl-auto=none

在application.properties。

最新更新