The official website of Hibernate tools: http://hibernate.org/tools/
Step1, install hibernate Tools, build a Dynamic Web project named "Test".
Step2, with MySQL as an example, set up the corresponding test database and table as follows:
[SQL]View PlainCopy
- MYSQL> USE TEST;  
- DATABASE CHANGED  
- MYSQL> SHOW TABLES;  
- +----------------+
- | TABLES_IN_TEST |  
- +----------------+
- | CUSTOMER       |  
- | login |
- +----------------+
- 2 rows in set (0.10 SEC)
Step3, copy the MySQL JDBC Driver Library (Mysql-connector-java-5.0.8-bin.jar) to the Lib directory.
Step4, using hibernate tools to generate Hibernate cfg.xml. Such as:
Directly by default go to the next configuration interface, configuration such as:
After clicking Finish, it will generate the following XML configuration file (Hibernate.cfg.xml):
[HTML]View PlainCopy
- <? XML version= "1.0" encoding="UTF-8"?>
- <! DOCTYPE hibernate-configuration Public
- "-//hibernate/hibernate Configuration DTD 3.0//en"
- "Http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
- <hibernate-configuration>
- <session-factory>
- <property name="Hibernate.connection.driver_class">org.gjt.mm.mysql.driver</ Property >
- <property name="Hibernate.connection.password">[email protected]</ Property>
- <property name="Hibernate.connection.url">jdbc:mysql://localhost:3306/test</ Property >
- < name="Hibernate.connection.username">root</ Property >
- <property name="Hibernate.dialect">org.hibernate.dialect.mysql5dialect</ Property>
- </session-factory>
- </hibernate-configuration>
Step5, use hibernate tools to generate the Console configuration for hibernate. Such as:
When you click Finish, it generates a configuration file, such as:
Step6, use hibernat tools to generate reveng.xml configuration for hibernate. Such as:
Directly by default go to the next configuration interface, configuration such as:
After clicking Finish, it will generate the following XML configuration file (Hibernate.reveng.xml):
[HTML]View PlainCopy
- <? XML version= "1.0" encoding="UTF-8"?>
- <! DOCTYPE hibernate-reverse-engineering Public
- "-//hibernate/hibernate Reverse Engineering DTD 3.0//en"
- "Http://hibernate.sourceforge.net/hibernate-reverse-engineering-3.0.dtd" >
- <hibernate-reverse-engineering>
- <table-filter match-catalog="test" match-name="Customer" />
- <table-filter match-catalog="test" match-name="login" />
- </hibernate-reverse-engineering>
STEP7, the last step, generate the mapping file and Java code . Such as:
After clicking Run, it will generate the following mapping files and Java code files, such as:
Reference: http://www.cnblogs.com/abllyboy/archive/2010/12/23/1914577.html
Use of Hibernate Tools for Eclipse