Configure and use Hibernate Tools under Eclipse

Source: Internet
Author: User

This article transferred from: http://radiumwong.iteye.com/blog/358585

Hibernate tools can generate Pojo files in reverse engineering by accessing an already established database.
Let's say today how to use hibernate tools to generate Pojo.

1. First, to go to Hibernate's website to download this toolkit. A zip compressed file of about 14M.
Http://jaist.dl.sourceforge.net/sourceforge/jboss/HibernateTools-3.2.4.Beta1-R200810311334.zip


2. Unzip the downloaded files and release the two folders and contents of features and plugins. When you are finished, copy the two folders to the Eclipse directory (the two folders exist by default in Eclipse, and copy directly).

3, to this step hibernatetools installation even if the end, the following start configuration and specific use. Start by selecting the SRC directory under the project, then right-new->other->hibernate->hibernate the Configuration File (cfg.xml), select Next in the Pop-up window and go to the options below.


Note that there are several items in this place that must be filled in. They are database dialect (db dialect), Driver class (Database driver), Connection URL (link string), and username and password (user name and password to access the database).

The diagram uses the configuration of the MySQL5 database, and Vane is a database that has been created in my machine. The use of other databases can be slightly different.

Select Finish after filling.


4. Choose Eclipse's drop-down menu window->show view->other->hibernate->hibernate configurations, now you can see the Hibernate configuration window. Right-click Add configuration in the window and the Edit Configuration window appears.

You need to give the configuration a name and then select the current project in project.

Click OK.


5, if the previous step of the configuration is correct, then hibernate in the configuration window can see Hibernate access to the database to obtain the data information.

If there is no successful access, the dialog will pop up and you can determine what is wrong with your project based on the information you are prompted to do. Most of the cases are caused by the lack of MySQL drivers in the project.

If there is nothing to solve the problem, you can give me a message, I will work with you to study.

Drive packages are official:
Http://dev.mysql.com/downloads/connector/j/5.1.html


6, 5th step successful words can be the last step to generate code work, what an exciting moment ah O (∩_∩) o ...

No hurry, here we do a preparatory work first. Right-click the Eclipse's toolbar, select Customize Perspective->commands->hibernate Code Generation, and click OK. This adds the Hibernate icon to the toolbar.

Left-click the down arrow to the right of the icon and select Hibernate Code Generation configurations from the drop-down menu.
Make the final settings in the pop-up window.

The output directory under the main tab selects the location of the makefile and selects it to the SRC directory. Reverse Engineer from JDBC connection This box is important, just pick it up. The package chooses to generate Pojo, and can name it on demand. Reveng.xml This place choose Setup->create new-> project name->next->refresh->include->finish, done! (Reveng is not a transformer ~)

Under the Exporters tab, select the file you want to generate, where domain code (. java) is selected, and the second Hibernate XML Mappings (. Hbm.xml) is the build configuration file, If you decide to use annotation in your project, you can ignore this one.

Last step, click Run to get the Pojo code you want. Feel dissatisfied with their own changes slowly, you can also write a format code of the program, this next time.

Configure and use Hibernate Tools under Eclipse

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.