At the stage of the development project, when the database table for the project has been designed, the next step is to develop it. But there are a lot of tables in a project, and the first step in development is to create the entity classes for the corresponding database tables in the project, which is a manual work, and it needs to be very careful, and it's a waste of time.
However, the use of myeclipse reverse function is very labor-saving pull.
The reverse generation entity class is roughly divided into 3 steps.
Step one: Connect the database via MyEclipse
1. Open database view in MyEclipse
Window--> Open Perspective--> myeclipse Database Explorer, and goes to the DB view.
If this is the first time you enter the view, there will only be a default database MyEclipse Derby, and the other databases are added by the user themselves.
2. Click the right mouse button in the blank to--> new .... A parameter form for the connection database pops up.
Oracle data is used here as an example.
Fill in the appropriate form according to your own situation.
After filling out the information, it is best to click the test Driver button to test whether you can connect to the database. After entering the login password for the database, the dialog box pops up if the connection succeeds
"Database connection successfully established", then prove that MyEclipse has been connected to your selected databases.
Click Finish to complete this step.
3. In the database view, select the database connection you just created, "AVB", right-click, and select "Open Connection".
At this point, the database you are connecting to can be viewed in the view.
However, myeclipse all the tables in the database, you just have to find your own users, double-click, expand, and then expand the table, then you can see the table you want.
Step Two: Create a new project
1. Create a new Web project, this is not said, we all know how to do.
2. First create a package in this project that you want the entity to store. In this way, the generated entity of the province can import the package incorrectly, and finally manually change the package name.
3. The selected item right key--> MyEclipse--> ADD Hibernate capabilities.
A dialog box pops up, and in the Hibernate specification option, select Hibernate 3.3.
If you need to add annotations to the entity, select the Add Hibernate annotations next to it Support
4. Click Next to select the place you want to store the Hibernate.cfg.xml profile, the default src directory,
Directly click Next, in the next view in the DB Driver Drop-down box to select the database driver you just connected to the name, my is "AVB." After the election of the other information will be automatically completed, and then they are connected to the database password to fill in OK.
Next click Next, select the package you want to store to create the Hibernatesessionfactory class, and build a new one for your own needs.
Click Finish to complete.
After this step is done, you will find that there are some changes in the icon for the project. ----->>. This time, the project has a hibernate ability to reverse.
This is the content of the generated hibernate.cfg.xml file.
Step three: Reverse-generate entity classes
Back to DB Browser view, select the table you want to reverse the generated entity, right-click--> Hibernate Reverse Engineering ...
Select the package you want to store when you need to generate the entity.
Create POJO<>DB Table mapping infomation This option is to select the configuration from the table to the simple Java object (that is, Pojo) and put the following add Hibernate mapping Annotations to Pojo, whatever else, this option is used to "add mapping annotations to the Pojo object", the option above which is used to create XML, is said to be not very useful, use annotation bar.
Create a Hibernate mapping file (*.hbm.xml) for each database table This option creates a ". Hbm.xml" Profile for every entity class.
Add Hibernate mapping Annotations to Pojo
Click Next, Option ID Generator, to allow you to select the primary key ID generation strategy.