In a new (read: no legacy) project I am using JPA 2 with some simple annotated entities and a persistence unit (src/main/resources/META-INF/persistence.xml). That PU contains the "hibernate.hbm2ddl.auto" property set to "create". When executing this in my container (recent Glassfish with MySQL DB) it works perfectly: The DB is created and all entities are written and can be read.
Except that PU I have no further configs such as "hibernate.properties" or "hibernate.cfg.xml" or so. I am just using Hibernate 4.x as JPA implementation asking it not to use any mappings but all @Entity classes. Fine.
I also have a test PU (src/test/resources/META-INF/persistence-test.xml) with a different PU name. When deploying that into an embedded Glassfish and a in-memory Derby DB using Arquillian, that also works fine with that test PU.
Now, I would not like Hibernate to auto-update my production PU and thus deactivated the auto-update. Instead, I would like to have Hibernate generating DDL files for me. And this is where my horror begins - for weeks now.
I assume that Hibernate is set up fine - given that everything works as described above. However, no matter what I try to get Hibernate just writing DDL files for me fails (best case: empty DDL file...).
I tried e.g. using Hibernate 3.7.x or 4.x with Hibernate3-Maven-Plugin, with "hibernate.hbm2ddl.outputfilename" via PU properties or programmatically via SchemaExporter, Configuration, Ejb3Configuration etc.
No matter what I tried, it never gave me the DDL script file. I read old and recent Hibernate (Tools) documentation, forums, blogs... nothing helped. Especially because most examples still utilised Hibernate config files and/or Ant...
Since I use Hibernate behind the scenes and only Maven, I would like to know what is the most simple approach to generate that DDL in Hibernate 4 and plain JPA 2? I am so confused, also because even in examples, the Maven plugin sometimes is configured via "<hibernatetools>" and sometimes via "<componentProperties>"... what is correct now? I also debugged into SchemaExporter but no luck yet...
Can someone please advice? I mean I see Hibernate creating my schema on-the-fly and always logging the issued SQL into STDOUT already for weeks now - so there must be a way just to capture that DDL also into a file!?!
Does not matter how - via code or via Maven - as long as it is straight ;)
Thanks and best regards,