1

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?

2
  • Why do you need to run Configuration.generateSchemaUpdateScriptList()? Commented Dec 2, 2014 at 19:11
  • Obviously because I want to get Hibernate's idea of how to update the schema to match the entities, but do something else with it rather than just apply it as is. Commented Dec 4, 2014 at 11:38

1 Answer 1

2

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 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.