title: How to know when the database is ready?
body: <p>Sometimes the createEntitymanagerFactory can take a while, specially if the database needs to be created.</p>
  
  <p>I'm using Flyway for my database and started finding issues during migration. Looking at the logs it seems like I'm trying to migrate before the tables have been created. For example</p>
  
  <pre><code>Table "XINCO_CORE_USER" not found; SQL statement:
  INSERT INTO `xinco_core_user` (`id`, `username`, `userpassword`, `last_name`, `first_name`, `email`, `status_number`, `attempts`, `last_modified`) VALUES (1, 'admin', '21232f297a57a5a743894a0e4a801fc3', 'Administrator', 'Xinco', 'admin@xinco.org', 1, 0, now()) [42102-168]
  </code></pre>
  
  <p>JPA is set up to create the tables. When I enable the logs in JPA it shows that the error above happens before JPA is done creating the database.</p>
  
  <p>Is there a way to listen on the JPA database to know when it is ready? I only found listeners for entities themselves but nothing for the PersistenceManager life cycle.</p>