Hi! I'm having kind of a problem with the Hibernate tool to generate the database schema.
I would like to mention that the application itself works perfectly. But I would like to generate the database schema in a SQL file in order to give it to my DBA.
In the ant task I have eliminated all the configuration that isn't relevant for the export (like database credentials, etc). I just have the data that is -in theory- necessary to generate the export. I'm using JTA and therefore, I'll stick to <jpaconfiguration>
Here the ANT tasks:
Code:
<target name="Generate DB Schema" depends="Compile bussiness classes that include the model">
<!-- Hibernate tasks definition -->
<taskdef name="hibernatetool" classname="org.hibernate.tool.ant.HibernateToolTask">
<classpath refid="master-classpath-with-compiled-bussiness-classes-including-the-model-with-annotated-JPA-entries"/>
<classpath>
<pathelement path="${resources.dir}/libs/hibernate-3.3.1/all-hibernate-jars-including-tools-and-jbosscommons"/>
</classpath>
</taskdef>
<!-- Lets create a temporary Hibernate configuration file to store those properties I need for the export -->
<!-- I will need ONLY the dialect and the "autodectection" magic -->
<propertyfile file="${dest.dir}/hibernateProperties.properties">
<entry key="hibernate.dialect" value="mydialectwhateveritis"/>
<entry key="hibernate.archive.autodetection" value="class,hbm"/>
</propertyfile>
<hibernatetool destdir="${dest.dir}" >
<classpath refid="master-classpath-with-compiled-bussiness-classes-including-the-model-with-annotated-JPA-entries"/>
<!-- Notice that my "PU" is defined in the classpath/META-INF/persistence.xml -->
<jpaconfigurationp ersistenceunit="PU" propertyfile="${dest.dir}/hibernateProperties.properties"/>
<hbm2ddl
export="false"
update="false"
drop="true"
create="true"
outputfilename="exportschema.sql"
delimiter=";"
format="true"
haltonerror="true"
/>
</hibernatetool>
</target>
Aha, easy. Now, lets see the /META-INF/persistence.xml. Just to make it work I have removed all the information that is not relevant. This is: everything (because it isn't needed by the export schema)
But I have force the exclude-unlisted-classes=false to make sure hibernate autodetects.
Code:
<persistence-unit name="PU" transaction-type="JTA">
<!-- Autodetect mapping classes -->
<exclude-unlisted-classes>false</exclude-unlisted-classes>
</persistence-unit>
Now, it doesn't work. The task runs smothly but no class is detected so no export is done :-(
In order to test if the .hbm files are autodetected, I created a HBM file somewhere lost in the classpath like this:
Code:
<database-object>
<create>
<![CDATA[
CREATE TRIGGER hibernate_is_weird
]]>
</create>
<drop>DROP TRIGGER hibernate_is_weird</drop>
</database-object>
I run the task and... yes, It's detected and included in the export.
Why the HBM are detected but not the annotated classes? Do I have to set anything else?
Thanks!
Hibernate tool version: latest (3.2.4.Beta1)