Como usar a classe Hibernate SchemaUpdate com um persistence.xml do JPA?
Eu tenho um método principal usando SchemaUpdate para exibir no console quais tabelas alterar / criar e funciona bem no meu projeto Hibernate:
public static void main(String[] args) throws IOException {
//first we prepare the configuration
Properties hibProps = new Properties();
hibProps.load(Thread.currentThread().getContextClassLoader().getResourceAsStream("jbbconfigs.properties"));
Configuration cfg = new AnnotationConfiguration();
cfg.configure("/hibernate.cfg.xml").addProperties(hibProps);
//We create the SchemaUpdate thanks to the configs
SchemaUpdate schemaUpdate = new SchemaUpdate(cfg);
//The update is executed in script mode only
schemaUpdate.execute(true, false);
...
Gostaria de reutilizar esse código em um projeto JPA, sem nenhum arquivo hibernate.cfg.xml (e nenhum arquivo .properties), mas um arquivo persistence.xml (detectado automaticamente no diretório META-INF, conforme especificado pela especificação JPA) .
Eu tentei essa adaptação muito simples,
Configuration cfg = new AnnotationConfiguration();
cfg.configure();
mas falhou com essa exceção.
Exception in thread "main" org.hibernate.HibernateException: /hibernate.cfg.xml not found
Alguém fez isso? Obrigado.