The good news is that the problem is resolved, but in case others hit the same problem, I wanted to post this. Also, I have some questions about what I was doing wrong to make the process of exporting the simplest possible schema a bit challenging. As always thanks in advance for any assistance.
I wanted to test the simplest case of creating a class with an annotation and using SchemaExport to create the database table. Following the documentation at:
https://www.hibernate.org/hib_docs/tool ... le/#d0e820, I set up the hibernateTool task definition, although it seemed that I needed many more jars that just hibernate-tools.jar, hibernate3.jar, freemarker.jar, {jdbc.driver.jar}. In particular, I needed jars for classes such as: LoggerFactory, StaticLoggerBinder, AnnotationConfiguration, TemplateLoader. I added all the necessary jars to my build.xml, but I was wondering why they weren't listed in the above url. I saw posts from others along similar lines - I wonder what we are all missing.
After fixing the above and adding my POJO classes to the "toolslib" path, I was able to run the hbm2ddl target. But the sql file that was generated was empty.
My build.xml looks like:
Code:
<path id="toolslib9">
<path location="${hibernate.plugin.tools.dir}/hibernate-tools.jar" />
<path location="${hibernate.plugin.tools.dir}/freemarker.jar" />
<path location="${hibernate.plugin.hibernate.dir}/commons-logging-1.0.4.jar" />
<path location="${hibernate.plugin.hibernate.dir}/hibernate3.jar" />
<path location="${hibernate.required.lib.dir}/freemarker.jar" />
<path location="${hibernate.annotations.dir}/hibernate-annotations.jar" />
<fileset dir="${hibernate.annotations.lib.dir}">
<include name="**/*.jar"/>
</fileset>
<fileset dir="${hibernate.annotations.lib.test.dir}">
<include name="**/*.jar"/>
</fileset>
<path location="${jdbc.driver.jar}" />
<path location="${classes.dir}" />
</path>
<taskdef name="hibernatetool"
classname="org.hibernate.tool.ant.HibernateToolTask"
classpathref="toolslib9" />
<target name="schemaExport">
<hibernatetool destdir="ddl">
<annotationconfiguration configurationfile="hibernate.cfg.xml"/>
<hbm2ddl export="true"
create="true"
delimiter=";"
format="true"
haltonerror="true"
outputfilename="create-tables.sql"/>
</hibernatetool>
</target>
My hibernate.cfg.xml is:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">org.gjt.mm.mysql.Driver</property>
<property name="hibernate.connection.password">x47b2lkp</property>
<property name="hibernate.connection.url">jdbc:mysql://192.168.2.200/potluck</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</property>
<mapping class="com.rb.potluck.Person" />
</session-factory>
</hibernate-configuration>
And my Java class is:
Code:
package com.rb.potluck;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import org.hibernate.annotations.Entity;
@Entity
public class Person {
private Integer id;
private Integer version;
private String emailAddress;
@Id
@GeneratedValue
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
// More getters, setters removed for brevity
}
Everything seemed to be as simple as possible - but nothing in the resulting SQL file. No errors from the ant command, nothing relevant in ant -debug. No errors in the Eclipse error log.
The problem turned out to be the import statement in my Person class. Rather than using:
Code:
import org.hibernate.annotations.Entity;
I changed to:
Code:
import javax.persistence.Entity;
And then everything worked. Don't know if anyone else is likely to make the wrong import choice - but I thought I would post anyway. If anyone can help me understand the need for all the extra jars, that would be great.
One last comment - I had started by trying to "Run Schema Export" in the Hibernate Configurations view, but it didn't work, so I switched to the ant based approach above. I would start the "Run Schema Export", get the confirmation dialog box and then nothing further - no errors, no feedback, just silence. My searching indicates that this is a known problem, but I was interested in confirming that.
Thanks again!
RB