Hibernate learning- ing and hibernate ing

Source: Internet
Author: User

Hibernate learning- ing and hibernate ing

Learning Record O (lead _ lead) O. If you happen to pass by, I hope you can stop and take a look. I hope you will be grateful for the shortcomings ~

Tools used:

1. eclipse 2, hibernate compressed package (hibernate_4.3.11) 3. mysql

Preparations: Create a project --> import the hibernate. jar package --> compile the hibernate. cfg. xml configuration file to connect to the database.

Write a class to read hibernate. cfg. xml

 

1. One-to-many (example: a department has multiple employees)

1. Create a table (Employee table and dpet Department table)

① Employee class

② Configure Employee. hbm. xml ing file, and in hibernate. cfg. <mapping resource = "com/sw/entity/Employee. hbm. xml "/>)

③ Dept class

 

④ Dept. hbm. xml configuration file, and register it in the hibernate. cfg. xml file (<mapping resource = "com/sw/entity/Dept. hbm. xml"/>)

⑤ Create a table

 

2. Add data:
Add multi-terminal data first, then add one end of data, and then associate the data in the Multi-terminal with one end of data. In the database, the insert statement is executed first, and then the update statement is executed to modify the association relationship, which is inefficient.

 

 

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.