Legacy database to POJO 关键字: Hibernate Tools
1,DownloadandinstallHibernateToolplugin
2,RunHibernateCodeGenerationConfiguations
2.1,setupreveng.xml(chooselegacytables)
2.2,chooseexporters(javaand/orhbmfiles)
3,Runtheconfiguraitontogeneratecodesorhbmfiles.
3.1javafileProduct.java
packagetest;
//GeneratedJul21,20102:25:51PMbyHibernateTools3.2.2.GA
/**
*Productgeneratedbyhbm2java
*/
publicclassProductimplementsjava.io.Serializable{
privateIntegerid;
privateStringno;
privateStringname;
publicProduct(){
}
publicProduct(Stringno){
this.no=no;
}
publicProduct(Stringno,Stringname){
this.no=no;
this.name=name;
}
publicIntegergetId(){
returnthis.id;
}
publicvoidsetId(Integerid){
this.id=id;
}
publicStringgetNo(){
returnthis.no;
}
publicvoidsetNo(Stringno){
this.no=no;
}
publicStringgetName(){
returnthis.name;
}
publicvoidsetName(Stringname){
this.name=name;
}
}
3.2,mappingfileProduct.hbm.xml
<?xmlversion="1.0"?>
<!DOCTYPEhibernate-mappingPUBLIC"-//Hibernate/HibernateMappingDTD3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!--GeneratedJul21,20102:25:51PMbyHibernateTools3.2.2.GA-->
<hibernate-mapping>
<classname="test.Product"table="product"catalog="MySQL">
<idname="id"type="java.lang.Integer">
<columnname="ID"/>
<generatorclass="identity"/>
</id>
<propertyname="no"type="string">
<columnname="NO"length="100"not-null="true"unique="true"/>
</property>
<propertyname="name"type="string">
<columnname="NAME"length="100"/>
</property>
</class>
</hibernate-mapping>