1. Preface
Many people are using myeclipse, many companies also use the Hibernate framework, in the old version of Hibernate, because there is no annotation, we need to write two files to maintain the relationship between the table and the object, write a class, It is necessary to write a hbm.xml file, the database table is less than the matter, but more trouble, to a handwriting is a very waste of time, there may be wrong. The new version of Hibernate joins the form of annotation to map the relationship between objects and database tables, although there is no need to write hbm.xml files, but there are a lot of database tables that need to write many classes. Why don't we find a tool to help us generate these files automatically? MyEclipse can do it, let me explain how to use MyEclipse to generate the files required for hibernate.
2. Open MyEclipse
3. Establishment of MyEclipse project
4. Select Web Project
5. Open the database perspective
In the upper right corner of MyEclipse
Click the right button
Add the driver required to connect to the database
Test connectivity
After the China Unicom finish will be
6. Add hibernate support to your project
Let's go back to myeclipse perspective.
Select the project and add hibernate support
7. Select some options
Select the connection you just created in the database perspective
Upon completion
8. Reverse Generation
We're back in the database perspective.
Open Data Connection
Open the connection you just created, and then open the table under the user name
This is the She user table, we select the table to be generated in reverse, you can select multiple, and then right-click
Click Hibernate Reverse Engineering ...
Select your project's src directory, fill in a reverse build, and under which package the class is placed
Create a Hibernate mapping file (*.hbm.xml) This sentence means to generate classes and hbm.xml files, if you want to generate annotation files Please select the following Add Hibernate mapping Annotations to Pojo that option
This step you can choose nothing, if you determine that the database table has a primary key, and know how to generate, you can select the ID Generator
If the UUID is generated, you can select
This step is not optional, you can also choose Next.
Include referenced tables (a->b)
Include referenced tables (a<-b)
These two must choose, otherwise myeclipse can not give you to generate a one-to-many, many-to-many mappings, if only want to generate a single map, you can remove a, generally we have to choose, two-item mapping.
In the back MyEclipse perspective, view the project
We see that the project has generated mapping files and classes.
A relational map has been generated
Annotation Way of
Generating Hibernate class files and Hbm.xml files from MyEclipse