SSH (ix) Eclipse uses the Hibernate plug-in to reverse generate entity classes and mapping files

Source: Internet
Author: User
Tags jboss

The development of the general DAO layer is this, the first database design, what e-R diagram, and so on, and then select a database products, to build a good table. Finally, the Java entity and mapping file are generated in reverse, which guarantees consistency and convenience.

If you use MyEclipse, reverse is easier, use eclipse must use Plug-ins, but myeclipse fees, some commercial products must pay attention to copyright issues.

Here's how to generate entity classes and configuration files using Eclipse.


1, download Hibernate plugin, open eclipse,help>install new software menu, name casually, URL is: http://download.jboss.org/jbosside/ Updates/stable, choose what JBoss comes with data ... Directory, there are Hibernate tool below. Installation.


2, add database information in eclipse:


Open Data Source Explorer, as shown in the following figure:


Select New ... ,


Select the appropriate database product, Next,


Drivers that key. The button behind the drive jar position, fill in the database information, finish.


The above information shows that the Eclipse connection database was successful.

3, add Hibernate configuration:

Open Window>show view>other and select Hibernate Config under the Hibernate menu, as shown below,


The Hibernate Configuration tab appears in the Console tab, as shown in the following figure:


If you have never configured Hibernate, then this is empty, the blank right click, select Add one, if configured, will display the configuration file. See below for how to add a new configuration. Right-click the blanks, as shown below:


After you select Add, the following image appears:


Above is the configuration of the Main tab, which focuses on the configuration of the database connection, using the data source that was previously configured in step 2nd. If you want a hibernate profile, you can have eclipse generate a new configuration file in the configuration file option, and not build it.

Then, as shown in the following figure, configure the Option tab's dialect,


Finally click OK, and a new hibernate config will be generated.

4, add hibernate related buttons to the toolbar:


After entering:


Check Hibernate code generate, click OK, there will be a more than a button in the following image:



5, configure Hibernate code generation:

Select the Hibernate Code in the above diagram ... Options


Can only be filled in the way above, main tab, console configuration is previously configured hibernte config,reveng.xml words setup,create New, the following figure:


To select the location of the XML file, click Next instead of finish to find the data source according to the previous Hibernate config, showing the following figure:


The first left list is empty, you need to click Refresh, then select the database, select the table, include, and this is the entity class and configuration file for the database table to be generated. Finish


Re-Configure the Exporters tab:


Tick which files are generated.

Finally configure the Common tab, character set:



Click Run to have the generated file:


To illustrate the point is that if you want to reverse the generation of associations, such as One-to-many these, then the underlying database to build the table will have to add foregn key constraints, or the resulting configuration file will not have associated information, but a separate sheet.

If there is a foreign key constraint when the table is built, the final One-to-many association is a two-way One-to-many association.


Summarize:

The steps are roughly 1, configure Data source 2, configure Hibernate 3, and configure Hibernate code Geration;4,run.

Related Article

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.