Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hibernate "generated by hibernate tools"

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?

like image 410
fudge Avatar asked Jun 15 '11 06:06

fudge


2 Answers

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.

like image 113
CuppM Avatar answered Oct 06 '22 19:10

CuppM


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.

like image 31
Tristan Avatar answered Oct 06 '22 20:10

Tristan