Reference: http://www.cnblogs.com/mingziday/p/4475124.html
In the SSH framework, if the database is designed first, then the next step is to generate the entity Java class and the Hbm.xml configuration file from the database table. In the latest development framework, annotations have been supported to avoid cumbersome hbm.xml configurations, and we can use the Hibernatetools tool to perform transformations from table to entity Java classes.
1, first install the Hibernatetools plug-in to eclipse
Open Eclispe and follow the steps below to complete the plug-in installation
Help > Install New software ... > Work with:
http://download.jboss.org/jbosstools/updates/stable/luna/
2. After the plug-in installation is successful, create a new hibernate.cfg.xml configuration file, which configures the settings of some linked databases to help Eclipse link your database tables
Click Add Configuration
In the Configuration box that pops up, select Project, Hibernate version, click Setup after Configuraton file
Configure your database link parameters in the configuration file Setup interface, click Finish to generate the profile
You can modify the generated configuration file Hibernate.cfg.xml, in graphical form, such as you can add some properties
At this point, your eclipse should be able to link to the database table.
3, after the configuration file is generated, that is, you can link to the database, the following can be generated from the database table we want Java files
Click Run->hibernate code Generation
Select the output path, package path, and so on in the interface, and the console configuration defaults to the configuration we built in the previous step.
The Export tab sets the files that we want to output.
After Reveng.xml click Setup, set the tables you want to output, for example we only output student table (This step will generate a configuration file hibernate.reveng.xml)
Finally click Finish, and the resulting file includes Tstudenthome.java, Tstudent.java
Tstudent.java is the annotated entity class that we want to generate.
/*** Tstudent generated by Hbm2java*/@Entity @table (name = "T_student", Catalog = "Happycardata")public class Tstudent implements java.io.Serializable { private Integer stuid; private String stunetname; private String Stupassword; private String sturealname; private String stuemail; private String stuimg; private String stuinfo; ..}
The overall step is not too cumbersome, if the table is more, you can save a lot of development effort. After you have designed the table structure, you can generate a primary version of the Java file at once, and then manually modify it on the basis of the primary version of the Java file, rather than relying solely on the tool generation. After all, manual modification is more controllable and more consistent with developers ' intentions.
Reference files:
http://www.tuicool.com/articles/7zq22q
http://blog.csdn.net/lisq037/article/details/9057907
Using Hibernatetools to generate annotated Pojo from database tables