0

Sometimes the createEntitymanagerFactory can take a while, specially if the database needs to be created.

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

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]

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.

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.

javydreamercsw
  • 5,363
  • 13
  • 61
  • 106
  • Obviously JPA has nothing to do with creating a database. Some implementations may provide that, but it is not JPA. – DataNucleus Aug 03 '12 at 06:30

1 Answers1

1

I believe the best solution is to let Flyway create the tables as well instead of sharing the work with JPA.

Have a look at this question and its chosen solution. There you can see how to cleanly tie Flyway into the Hibernate lifecycle.

Having said that, there may be better ways I'm just not aware of.

Community
  • 1
  • 1
Axel Fontaine
  • 34,542
  • 16
  • 106
  • 137