When the EntityManagerFactory is bootstrapped asynchronously, the DataSourceSchemaCreatedEvent is published off the main thread. This means that any data scripts will be applied off the main thread as well. I think a consequence of this is that the application context may have completed refreshing before the DataSource is fully initialised. I think we need to confirm if this is the case and then decide if the behaviour is acceptable.

Comment From: wilkinsona

At least part of this behaviour is due to Framework allowing application context refresh to complete before the bootstrapping of the entity manager factory has completed. This creates a race condition where, after context refresh completing, the state of the database is unknown. For example, Hibernate may have initialised the database's schema or it may not. I've opened SPR-17334.

Comment From: wilkinsona

The Framework issue has been moved to the 5.x backlog. That ties our hands quite a bit. My feeling is that we may just have to live with this. I'm reluctant to add something ourselves that will be superseded by something in Framework at some point with no guarantee that it would have exactly the same behaviour.