When I generate the hibernate classes in eclipse all the class files are being updated although now real change was made in the database. The only change in most of the files is the comment line: // Generated Jun 15, 2011 6:50:40 AM by Hibernate Tools 3.4.0.CR1.
The change of this line on each regeneration is not convenient since it's disrupts the tracking of changes in SVN.
Is there away to instruct the generation process not to generate this line?
I found this: https://forum.hibernate.org/viewtopic.php?f=6&t=989777&view=next
I use Windows 7 and NetBeans 7, so the hibernate-tools.jar
file was found here: C:\Program Files\NetBeans 7.0\java\modules\ext\hibernate
. Since the Program Files directory is normally read only, I had to open the jar
using WinZip that was opened with Admin rights. NetBeans has to be closed in order to modify the jar
file.
Then I just navigated to the /pojo/Pojo.ftl
file (for the generated .java
file) and the hbm\hibernate-mapping.hbm.ftl
file (for the generated .hbm.xml
file) and opened them in Notepad. I removed just the $(date)
part so I retained the Hibernate version used. When I saved the files in Notepad, Winzip detected the changes and asked me if I wanted to update the .jar
file.
Then when I restarted NetBeans and did a regen of my files, the date was gone. Kind of a pain to do, but it works.
Customizing the freemarker template (as explained by CuppM) is a way to do it. You are not forced to put the customized template back in the jar though. For example, if you use hibernate tool ant task, you can specify "templatepath" and hbmtemplate attributes :
<hibernatetool destdir="hibernate-model-gen/pojo" templatepath="hibernate-model-gen/customized-templates">
<jdbcconfiguration configurationfile="hibernate-model-gen/hibernate.cfg.xml" packagename="open.pub.proto.core.model" revengfile="hibernate-model-gen\gen-conf\hibernate.reveng.xml" detectmanytomany="true" />
<hbmtemplate templateprefix="pojo/" template="pojo/Pojo.ftl" filepattern="{package-name}/{class-name}.java">
<property key="jdk5" value="true" />
<property key="ejb3" value="true" />
</hbmtemplate>
</hibernatetool>
Also, it's a good practice to generate pojos in a dedicated directory, not on source code pojos. You can then copy only pojos which have changed on soure code pojos.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With