All i wanted was to generate ddl from JPA annotations. Little did i know it would be such a can of worms. First, I ran into the nasty
Persistence unit not found. Had to find source code for Hibernate tools JPAConfigurationTask and Ejb3Configuration to see where they expected the persistence.xml to be.
The answer is: on the classpath and inside META-INF. Here's the structure for my web app, just to be able to run the tool:
/META-INF/classes/META-INF/persistence.xml
It works as long as your META-INF/persistance.xml is on the classpath.
Next thing failed in the ant build: javassist.jar missing. This is from JBOSS's project:
https://sourceforge.net/project/showfil ... e_id=80766
Once all of that was set, i was finally able to run my hibernate tool to generate DDL from annotations.
ant script:
Code:
<taskdef
name="hibernatetool"
classname="org.hibernate.tool.ant.HibernateToolTask"
classpathref="classpath.base" />
<target name="jpa_ddl" depends="compile">
<hibernatetool destdir="${config}">
<classpath>
<path location="${classes}"/>
</classpath>
<jpaconfiguration persistenceunit="p1" />
<hbm2ddl
export="false"
update="false"
drop="true"
create="true"
outputfilename="db_schema.sql"
delimiter=";"
format="true"
haltonerror="true"
/>
</hibernatetool>
</target>
persistence.xml in {classpath}/META-INF/
Code:
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
version="1.0">
<persistence-unit name="p1" transaction-type="RESOURCE_LOCAL">
<class>net.xyzpackage.jpa.Property</class>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
</properties>
</persistence-unit>
</persistence>
[/code]