Regression in ORM 6. I think it’s specific to ORM 6.2, because I’ve never encountered this problem with ORM 6.0/6.1, but I’m not 100% sure (maybe the problem just wasn’t as visible in Hibernate Search before). The scenario:
- Hibernate ORM boots. While building the session factory, it calls sessionFactoryCreated on all session factory observers.
- In ORM 6.2, this means in particular calling org.hibernate.boot.internal.SessionFactoryObserverForSchemaExport#sessionFactoryCreated, which successfully creates the DB schema.
- One of the next observers (say, Hibernate Search’s) throws an exception from sessionFactoryCreated (say, because the Hibernate Search mapping is invalid).
- Hibernate ORM catches that exception and attempts to close the session factory.
- Upon closing, the session factory calls sessionFactoryClosing on all session factory observers.
- In ORM 6.2, this means in particular calling org.hibernate.boot.internal.SessionFactoryObserverForSchemaExport#sessionFactoryClosing.
That last call fails with the following exception:
In Hibernate ORM 5, things were a bit different (e.g. schema creation/drop was not done in an observer, see https://github.com/hibernate/hibernate-search/pull/3396/commits/9b18a1ed3c096befab7243f1834428138ffd46b6 ), so it’s hard to pinpoint where the problem was introduced exactly; but I can say at least that we didn’t get that exception in Hibernate ORM 5 and the schema was properly dropped. I believe the problem is here: https://github.com/hibernate/hibernate-orm/blob/63715770e94f18137d9d63f7d105fafa62ca687f/hibernate-core/src/main/java/org/hibernate/internal/SessionFactoryImpl.java#L460 It seems odd that we close the service registry after closing each integrator? I’d expect closing the service registry to be one of the very last things we do. |