My project uses Spring, JPA, and Hibernate, so that all EntityManager’s are injected by Spring.
I need to access persistent classes’ meta data such as column lengths and optionality. The only way I know to obtain this information is through Hibernate’s Configuration.getClassMapping(String className). In a pure Hibernate project without JPA and Spring, you can keep the Configuration after creating a SessionFactory(i.e. new Configuration().configure().buildSessionFactory()), but since Spring uses LocalEntityManagerFactoryBean to create a SessionFactory in the form of EntityManagerFactory, I’m not sure where to get the Configuration.
If it is not possible to retrieve the Configuration from Spring, is there any other way to access a persistent class’ meta data?
Thanks.
It turns out that it is not possible. Spring creates an EntityManagerFactory in a standard way, using a PersistenceProvider implementation specified in the persistence.xml file. HibernatePersistence, which is Hibernate’s implementation of PersistenceProvider, does not keep the Configuration object after use. In order to expose the Configuration, you’ll need to implement PersistenceProvider on your own, which isn’t a big deal anyways.