MyEclipse using hibernate forward engineering and reverse engineering

Source: Internet
Author: User

1.myeclipse using hibernate forward Engineering, Hibernate's forward engineering refers to the process of generating database tables from Java entity classes, which conforms to the idea of Java programmer Object-oriented programming, and is also a more used idea in engineering design. The specific implementation process is as follows.


1). Manually create the Java Pojo object and add Hibernate anotation to the Pojo object. The purpose of this is to generate the hibernate mapping file through MyEclipse,


public class User {

private int uid;


Private String pwd;

Private String pname;


private String name;


/**

* @hibernate. ID generator-class= "native"

* @return

*/

public int Getuid () {

return UID;

}

public void SetUid (int uid) {

This.uid = UID;

}

/**

* @hibernate. Property column= "pwd" not-null= "true" length= "32"

* @return

*/

Public String getpwd () {

return pwd;

}

public void SetPwd (String pwd) {

This.pwd = pwd;

}

/**

* @hibernate. Property column= "PName" length= "32"

* @return

*/

Public String Getpname () {

return pname;

}

public void Setpname (String pname) {

This.pname = PName;

}

/**

* @hibernate. Property column= "Name" length= "16"

* @return

*/

Public String GetName () {

return name;

}

public void SetName (String name) {

THIS.name = name;

}


2) Myeclipst project name right click Myeclipst click Run Xdoclet, if you do not make a myclipse xdoclet configuration, you need to configure it before you can perform the above operation. The specific configuration method is, the project selected right click the properties select Myclipse->xdoclet Select Addstander in the Pop-up dialog box selected Standarhibernate.


3) After running Xdoclet, the hibernate mapping file is generated, and the database connection settings are configured in the Hibernate configuration file Hibernate.hbm2ddl.auto The tomcate will generate a table when the Create is restarted.


2. Generating Java Pojo and Hibernate mapping files from database tables


1). Prepare the database, if the name is TestDB, there is a user table


2). Switch perspective in the upper-right corner of MyEclipse, switch to MyEclipse Database Explorer

3). Then right-click on the left-hand side, select New (that is, create a new database connection, Driver name Sql2005_testdb, easy to explain, the rest is the same as usual), configure the connection to click Next, enter the next form, Select the Third radio button (Display the selected Schemas), then click the Add button on the right, that is, add your database, then click the Finish button, so that your database connection is created;

4). Switch to MyEclipse Java Enterprise perspective and create a Web Project, if it's called Testdemo

5). Right-click Testdemo, select MyEclipse, and then choose Add Hibernate capabilities, then the form is not changed, the default is to select the Hibernate3.1, click Next, and then come out this form does not have to change, Will generate a Hibernate profile (Hibernate.cfg.xml), click Next, a form will appear, in the DB driber that drop-down box select the database connection just configured (top sql2005_testdb), click Next, Then come out a form, this form is to let you choose where you want to put the hibernate files you generated, you can click on new to create an entity package, or not to create, if we now create an entity of the package bar (useful below), and then click the Finish button;

6). Next is the last step, then switch to MyEclipse Database Explorer, right-click on the sql2005_testdb you just created, select Open Connection, and expand to table below the DBO, Expand Table, right-click on the user table we created, choose Hibernate Reverse Engineering (This is the reverse build), come out a panel in Java src folder to select the project src directory, and then in Java Package on the selection just now we create a good entity in the project, the next is the top three check box can be checked, click Next, there will be a panel, this panel can be used without the tube, and then click Next, this panel also no tube, click Finish, The entity classes and mapping files are then generated.


MyEclipse using hibernate forward engineering and reverse engineering

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.