title: Spring Boot w/ JPA & H2: DB file created but nothing is persisted
body: <p>I'm having problems modifying this basic <a href="https://github.com/spring-guides/gs-accessing-data-jpa.git" rel="nofollow">Spring JPA example</a> to persist changes.</p>
  
  <p>I've modified the example as following:</p>
  
  <p>1) To the Application class, I added</p>
  
  <pre><code>@PropertySource("classpath:application.properties")
  </code></pre>
  
  <p>and refactored the data access code to be non static:</p>
  
  <pre><code>@Autowired EntityManager em;
  @Autowired CustomerRepository repository;
  @Autowired DataSource dataSource;
  @Autowired EntityManagerFactory emf;
  public static void main(String[] args) {
      ConfigurableApplicationContext run = SpringApplication.run(
              Application.class, args);
      Application app = run.getBean(Application.class);
      app.run();
      run.close();
  }
  public void run(String... args) {
      repository.save(new Customer("Jack", "Bauer"));
  </code></pre>
  
  <p>2) and put the application.properties in /src/main/resources:</p>
  
  <pre><code>spring.datasource.url: jdbc:h2:./database/bootDB;AUTO_SERVER=TRUE
  spring.datasource.driverClassName: org.h2.Driver
  spring.jpa.show-sql: true
  </code></pre>
  
  <p>Now, when I run the program, a bootDB is created, but without a Customer table. If I do change the Application class and add</p>
  
  <pre><code>@Bean
  public EntityManagerFactory entityManagerFactory() {
      HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
      vendorAdapter.setGenerateDdl(true);
  
      LocalContainerEntityManagerFactoryBean factory = new LocalContainerEntityManagerFactoryBean();
      factory.setJpaVendorAdapter(vendorAdapter);
      factory.setPackagesToScan("hello");
      factory.setDataSource(dataSource);
      factory.afterPropertiesSet();
  
      return factory.getObject();
  }
  </code></pre>
  
  <p>everything is fine. Yet, when I debug the previous version, the LocalContainerEntityManagerFactoryBean in the created SimpleJpaRepository for the CustomerRepository seems to be properly configured, since it contains </p>
  
  <pre><code>ConnectionPool[defaultAutoCommit=null; defaultReadOnly=null; defaultTransactionIsolation=-1;(...) url=jdbc:h2:./database/bootDB;AUTO_SERVER=TRUE; username=sa; (...) dataSource=null; dataSourceJNDI=null; (...)
  </code></pre>
  
  <p>Why doesn't any object gets persisted in the initial setup? Can I fix it in a shorter (or better) manner?</p>