I've a main method using SchemaUpdate to display at the console what tables to alter/create and it works fine in my Hibernate project:
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);
...
I'd like to reuse this code in a JPA project, having no hibernate.cfg.xml file (and no .properties file), but a persistence.xml file (autodetected in the META-INF directory as specified by the JPA spec).
I tried this too simple adaptation,
Configuration cfg = new AnnotationConfiguration();
cfg.configure();
but it failed with that exception.
Exception in thread "main" org.hibernate.HibernateException: /hibernate.cfg.xml not found
Has anybody done that? Thanks.