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.