MyEclipse Reverse engineering of Hibernate mode for entity classes generated from database

Source: Internet
Author: User

Previous article:

The o/rmapping thought that hibernate brings to us is correct, that is to design the entity object in the project from the angle of the face object, establish the Pojo, and then write the Hbm.xml map file to generate the data table. But in the actual development, we often start from the database design point of view to achieve our expected projects. Therefore, the generation from database tables to entity classes is detailed here.

Database: MySQL 5.1

MyEclipse version: 8.0M1

Hibernate version: 3.2

First, I set up the following e-r relationships in the database:

Students and Classes 1 pairs, students and courses many-to-many (the resulting intermediate table is: stu_course), students and identity cards: 1 to 1, students refer to the identity card primary key as a foreign key (unique).

The resulting table structure:



The preparations are ready, and below, we begin to reverse engineer.

Open the MyEclipse Database explore view as shown



Right-click in the blank area to create a new database object.

Click Add Jars to add the jar file to the database.

Fill in connection Url:jdbc:mysql://localhost:3306/hibernatetab2pojo

User name and password: root

Driver Name:com.mysql.jdbc.Driver

Once completed, you can click Test Driver, if successful, then next.

Go back to Java view, right click on the project, select Myeclipse-->add Hibernate capabilities

Then next select a directory to store automatically generated hibernate.cfg.xml files, generally without exception, placed in the SRC root, the next step to select the database object we set up the first step, and then select a directory to hold the auto-generated Hibernatesessionfactory tool class, which A hibernatesessionfactory tool class is a single instance that gets the session, and some other ways to close the session.
Finally, the most critical step is to generate the entity class.

Convert to MyEclipse Database Explorer view, open our databases: Hibernatetab2pojo, expand Tables, select All tables:



Then, right click, select Hibernate Reverse Engineering ...



Check: Create pojo<> ... , select Create a Hibernate ... , check update Hibernate ..... , and then next.


ID Generator: Check native (in my design table, ID is self-increment, if you want to try other friends can self-test)

Selection: Hibernate types

Tick all the other hooks.

Next, click Finish directly to generate the entity class and the corresponding Hbm.xml file. And the Hibernate.cgf.xml will be well configured.






MyEclipse Reverse engineering of Hibernate mode for entity classes generated from database

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.