Reputation: 9417
I'd like to run Configuration.generateSchemaUpdateScriptList()
. However Hibernate is configured using LocalContainerEntityManagerFactoryBean
. How do I get to the Configuration
object from a LocalContainerEntityManagerFactoryBean
instance? Or is there a better way to achieve this?
Upvotes: 1
Views: 623
Reputation: 9417
OK this was a two-days wall vs. head marathon, but in the end I found a solution, although it's somewhat hacky.
I cam across Hibernate's Integrator
, which is scarcely mentioned in the docs. Some more information about it can be found in the linked Hibernate JIRA issues HHH-5562 and HHH-6081. However, one can piece together enough information for a working example from a few sources once you know the keyword. Still it does not play well with Spring, a problem mentioned in this SO question.
So, the final solution was a bit hackish, but it works:
public class GetConfigIntegrator implements Integrator {
private static Configuration configuration;
public static Configuration getConfiguration() {
return configuration;
}
@Override
public void integrate(Configuration configuration, /* ... */) {
GetConfigIntegrator.configuration = configuration;
}
// Empty Integrator implementation...
}
As can be seen, this silly integrator simply stores the configuration in a static variable, so it can be accessed later. Not ideal, but faced with no options one rejoices finding such a path.
To register the integrator, the following file needs to be created, with one line per integrator class (full name), like so:
# src/main/resources/META-INF/services/org.hibernate.integrator.spi.Integrator:
<full package name>.GetConfigIntegrator
Upvotes: 2