hbm2ddl doesn't seem to allow only creating the SQL file with export=false, it has to have export="true" and update the database, or it will throw an NPE (stack trace below).
Looking at the code (SchemaExport line 311) it is because statement.getWarnings() is accessed but statement is null when export=false. The check for warnings should be inside the "if ( export ) ".
The workaround is to set export="true", obviously, but it would be nice if this was fixed. I searched JIRA but couldn't find any matching issue.
Hibernate version: hibernate-3.2.0.cr3
Ant task code
<target name="schema-recreate" depends="compile">
<hibernatetool destdir="">
<configuration propertyfile="${src.dir}/project.properties">
<fileset dir="${src.dir}">
<include name="model.hbm.xml"/>
</fileset>
</configuration>
<!-- NB doesn't work with export=false, get NullPointerException in SchemaExport -->
<hbm2ddl drop="true" create="true" export="false" update="false" outputfilename="../SQL/model.sql"/>
</hibernatetool>
</target>
Full stack trace of any exception that occurs:
Location: org.hibernate.tool.hbm2ddl.SchemaExport.execute(SchemaExport.java:202) Message:
schema export unsuccessful
Throwable:
java.lang.NullPointerException
at org.hibernate.tool.hbm2ddl.SchemaExport.execute(SchemaExport.java:311)
at org.hibernate.tool.hbm2ddl.SchemaExport.drop(SchemaExport.java:284)
at org.hibernate.tool.hbm2ddl.SchemaExport.execute(SchemaExport.java:186)
at org.hibernate.tool.hbm2ddl.SchemaExport.create(SchemaExport.java:133)
at org.hibernate.tool.ant.Hbm2DDLExporterTask.execute(Hbm2DDLExporterTask.java:55)
at org.hibernate.tool.ant.HibernateToolTask.execute(HibernateToolTask.java:160)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:275)
at org.apache.tools.ant.Task.perform(Task.java:364)
Name and version of the database you are using: Oracle 10gr2
|