title: Programmatic SchemaExport / SchemaUpdate with Hibernate 5 and Spring 4
body: <p>With Spring 4 and Hibernate 4, I was able to use Reflection to get the Hibernate Configuration object from the current environment, using this code:</p>
  
  <pre><code>@Autowired LocalContainerEntityManagerFactoryBean lcemfb;
  
  EntityManagerFactoryImpl emf = (EntityManagerFactoryImpl) lcemfb.getNativeEntityManagerFactory();
  SessionFactoryImpl sf = emf.getSessionFactory();
  SessionFactoryServiceRegistryImpl serviceRegistry = (SessionFactoryServiceRegistryImpl) sf.getServiceRegistry();
  Configuration cfg = null;
  
  try {
      Field field = SessionFactoryServiceRegistryImpl.class.getDeclaredField("configuration");
      field.setAccessible(true);
      cfg = (Configuration) field.get(serviceRegistry);
  } catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) {
      e.printStackTrace();
  }
  
  SchemaUpdate update = new SchemaUpdate(serviceRegistry, cfg);
  </code></pre>
  
  <p>With Hibernate 5, I must use some <code>MetadataImplementor</code>, which doesn't seems to be available from any of those objects. I also tried to use <code>MetadataSources</code> with the <code>serviceRegistry</code>. But it did say that it's the wrong kind of <code>ServiceRegistry</code>.</p>
  
  <p>Is there any other way to get this working?  </p>