title: How to create ddl file with spring data and java based configuration?
body: <p>I have my spring data JPA configuration up and running. I'd like to get a <strong>ddl sql file</strong> from my annotated entities.</p>
  
  <p>I know this has been asked many times. But I could not find something usefull explaing how to do this with java based spring configuration.</p>
  
  <p>This is my JPA set-up:</p>
  
  <pre><code>@Bean(name = BEAN_ENTITY_MANAGER_FACTORY)
  public EntityManagerFactory entityManagerFactory() {
      LocalContainerEntityManagerFactoryBean em = createLocalContainerEntityManagerFactoryBean();
      em.setDataSource(dataSource());
      em.setJpaVendorAdapter(jpaVendorAdapter());
      em.setPersistenceUnitName(getPersistenceUnitName());
      em.setPackagesToScan(getPackagesToScan());
      processOptionalProperty(Environment.HBM2DDL_AUTO, em);
      processOptionalProperty(HIBERNATE_JDBC_BATCH_SIZE, em);
      processOptionalProperty(EHCACHE_CONFIGURATIONRESOURCENAME_PROPERTY, em);
      em.afterPropertiesSet();
      return em.getObject();
  }
  
  @Bean(name = BEAN_HIBERNATE_JPA_VENDOR_ADAPTER)
  public HibernateJpaVendorAdapter jpaVendorAdapter() {
      HibernateJpaVendorAdapter adapter = new HibernateJpaVendorAdapter();
      adapter.setShowSql(Boolean.parseBoolean(getPropertyValue(HIBERNATE_SHOW_SQL_PROPERTY)));
      adapter.setDatabasePlatform(getPropertyValue(HIBERNATE_DATABASE_PLATFORM_PROPERTY));
      adapter.setGenerateDdl(true);
      return adapter;
  }
  </code></pre>
  
  <p>The hbm2ddl is set like this:</p>
  
  <pre><code>hibernate.hbm2ddl.auto=create
  </code></pre>
  
  <p>This configuration creates the necessary database tables at application start-up. How can I get an sql script containing all the ddl commands to set-up the DB?</p>