Use MyEclipse to automatically create PO classes, HBM files (mapping files), DAO

Source: Internet
Author: User

Original address: http://blog.csdn.net/fangzhibin4712/article/details/7179414

Prerequisites: Table SJZDFL table sjzdxx (using database MySQL)

Table SJZDFL (two fields Sjzdflid and SJZDFLMC)

Table SJZDFL Table Statements:

[SQL]View Plaincopy
    1. DROP TABLE IF EXISTS ' SJZDFL ';
    2. CREATE TABLE ' SJZDFL ' (
    3. ' Sjzdflid ' int (one) not NULL auto_increment,
    4. ' SJZDFLMC ' varchar (255) default NULL,
    5. PRIMARY KEY (' sjzdflid ')
    6. ) Engine=innodb DEFAULT charset=gb2312;

Table Sjzdxx (three fields Sjzdid and Sjzdflid and SJZDXXMC constraints: Sjzdflid as a foreign key for table SJZDFL)

Table SJZDXX Table Statements:

[SQL]View Plaincopy
  1. CREATE TABLE ' sjzdxx ' (
  2. ' Sjzzid ' int (one) not NULL auto_increment,
  3. ' Sjzdflid ' int (one) default NULL,
  4. ' SJZZXXMC ' varchar (255) default NULL,
  5. PRIMARY KEY (' Sjzzid '),
  6. KEY ' sjzdflid ' (' Sjzdflid '),
  7. CONSTRAINT ' sjzdxx_ibfk_1 ' FOREIGN KEY (' sjzdflid ') REFERENCES ' SJZDFL ' (' sjzdflid ')
  8. ) Engine=innodb DEFAULT charset=gb2312;



Steps:

1. Create a database connection

2. Add hibernate support to HibernateTest2

3. Use database tables to automatically create PO classes, HBM files (mapping files), DAO

1. Create a database connection

1.1 New Database connection

1.2 Configuring database connections

2. Add hibernate support to HibernateTest2

2.1 Adding Hibernate support to Project HibernateTest2

2.2 Adding Hibernate support

2.3 Add hibernate Support (config XML file)

2.4 Add Hibernate support (add database support)

2.5 Adding Hibernate support

3. Use database tables to automatically create PO classes, HBM files (mapping files), DAO

3.1 Back to MyEclipse databaseexplorer view

3.2 Configuring Hibernate mapping and App generation

3.3 Configuring Mapping Details

3.4 Configuring the Reverse engine details

3.5 Create complete (change package)

3.6 Using Test1.java Test

[Java]View Plaincopy
    1. Package com.test;
    2. Import java.util.List;
    3. Import Com.dao.SjzdflDAO;
    4. Import COM.PO.SJZDFL;
    5. Public class Test1 {
    6. public static void Main (string[] args) {
    7. Sjzdfldao Sdao = new Sjzdfldao ();
    8. list<sjzdfl> all = Sdao.findall ();
    9. For (SJZDFL sjzdfl:all)
    10. {
    11. System.out.print (Sjzdfl.getsjzdflid ());
    12. System.out.println (SJZDFL.GETSJZDFLMC ());
    13. }
    14. }
    15. }

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.