The pojo class generated by hbm2java in hibernate 3.2.x is always similar to the following:
Public class child implements java. Io. serializable {
Private int CID;
Private string childname;
Public int getcid (){
Return this. CID;
}
Public void setcid (int cid ){
This. cid = CID;
}
Public String getchildname (){
Return this. childname;
}
Public void setchildname (string childname ){
This. childname = childname;
}
}
However, if you use JDK or a later version, you always warn that the class lacks a static final long serialversionuid. How can you automatically add it when hbm2java generates the Java source code? This requires modifying the pojo template in the hibernate-tools.jar.
First, you extract the pojo/pojo. FTL file in the hibernate-toosl.jar, in <# If! Add static final long serialversionuid = 1l to the next line of pojo. isinterface ()>. The content of the entire pojo. FTL file should be as follows:
$ {Pojo. getpackagedeclaration ()}
// Generated $ {date} By hibernate tools $ {version}
<# Assign classbody>
<# Include "pojotypedeclaration. FTL"/> {
<# If! Pojo. isinterface ()>
Static final long serialversionuid = 1l;
<# Include "pojofields. FTL"/>
<# Include "pojoconstructors. FTL"/>
<# Include "pojopropertyaccessors. FTL"/>
<# Include "pojotostring. FTL"/>
<# Include "pojow.shashcode. FTL"/>
<# Else>
<# Include "pojointerfacepropertyaccessors. FTL"/>
</# If>
<# Include "pojoextraclasscode. FTL"/>
}
</# Assign>
$ {Pojo. generateimports ()}
$ {Classbody}
Then override the pojo. FTL file in the hibernate-tools.jar package.
Finally, run your ant again. The build. xml class will automatically be available without modifying the generated class: static final long serialversionuid = 1l;