I found a work around for this problem. The issue itself seems to revolve around the fact that Netbeans 6.5 (and I later versions up to this point) do not allow you to reverse engineer a database from an existing hibernate.reveng.xml
file. This is slated to be available in version 7.
The work around I found is to create an ant task to recreate the hbm.xml
and pojo java files. I currently have this hooked to happen when I do a clean and build, but I am going to try to find a way to to have it completely separate, since it will only need to be ran when the database schema changes.
To accomplish this when you do a clean and build though you need to edit your build.xml
file.
The first part is the libraries you will need. So add:
<path id="toolslib">
<path location="lib/hibernate-support/hibernate-tools.jar" />
<path location="lib/hibernate-support/hibernate3.jar" />
<path location="lib/hibernate-support/freemarker.jar" />
<path location="lib/hibernate-support/jtidy-r938.jar" />
<path location="lib/ojdbc14.jar" />
</path>
You should already have the hibernate-tools.jar, hibernate3.jar, and ojdbc14.jar files on you machine. So just change the path to them. The freemaker.jar and jtidy-r938.jar will need to be downloaded, as I did not have those.
Below this in the build.xml
you will need to add:
<taskdef name="hibernatetool"
classname="org.hibernate.tool.ant.HibernateToolTask"
classpathref="toolslib">
<classpath>
<fileset dir="lib">
<include name="**/*.jar"/>
</fileset>
</classpath>
</taskdef>
The last section you will need is the set to run in the post-clean section:
<target name="-post-clean">
<delete dir="src/*Put the foler where your pojos and hbm.xml files are located*"/>
<hibernatetool>
<jdbcconfiguration
configurationfile="src\hibernate.cfg.xml"
packagename="*the package where you want them recreated*"
revengfile="src\hibernate.reveng.xml"
detectmanytomany="true"
/>
<hbm2hbmxml destdir="src" />
<hbm2java destdir="src" />
</hibernatetool>
</target>
- The delete portion will delete the existing hbm and pojo files, before they are re-created.
- The
configurationfile
points to your main configuration file.
- The package name is the dot separated package you want them created in (
com.stackoverflow.pojo
for example).
- The
revengfile
is the reverse engineering xml file to use when creating the hbm and pojo files.
- The
hbm2hbmxml
will create the hbm.xml
files of your tables.
- The
hbm2java
will create the java pojo files of your tables.
Now to get the Oracle Timestamps to be something other than Serializable
, edit the hibernate.reveng.xml
file and add:
<type-mapping>
<sql-type jdbc-type="OTHER" hibernate-type="java.sql.Timestamp" />
</type-mapping>
just after the schema-selection tag.
So a clean and build and the timestamps will not be java.sql.Timestamp
instead of Serializable
objects.
This is a long answer I know, but this should also work for any other changes that you would have to set in the hibernate.reveng.xml
file (I think). I am no expert in hibernate, so your mileage may vary with this.
UPDATE:
So after some googling I found this site about custom ant tasks in Netbeans. So I simply changed the name of the target to be gen-dao
and now it does not run every time I do a clean and build, just when I specifically invoke it.