6. Create a “new hibernate configuration”
5
Goal:
connect Eclipse with the Data Base using a Hibernate bridge
Eclipse Hibernate
Hibernate.cfg.xml
Data Base
7. Create a “new hibernate configuration”
6
- Hibernate configuration tab, at the bottom
- Right bottom
- Add configuration
* This name is the same that is going to be used in the code generation configuration
8. Create a “new hibernate configuration”
7
Project: folder where is located the project
Database connection: Hibernate configured
Configuration file: folder where is located hibernate configuration file (fileName.cfg.xml)
9. Create a “new hibernate configuration”
8
Options Tab
Database dialect: MySQL
10. Create a “new hibernate configuration”
9
Classpath Tab
Classpath: you must include hibernate libraries into the path
13. Hibernate Reverse Engineering: hibernate.reveng.xml
12
Goal:
Create a file where is specified the number of tables used to obtained:
- POJOs (plain java objects with attributes and getter/setter methods)
- hbm.xml (mapping files which maps data base fields into class attributes)
16. Hibernate Reverse Engineering: hibernate.reveng.xml
15
1. Console configuration: choose the configuration created in step 1
2. Refresh (until a data base schema appears at the left box)
3. Click Include: include every table in the data base
3. Click Finish button
* The image above must be obtained as a result of applying the indicated steps
17. Result
16
* This file specified the tables contained within the data base which must be mapped
18. 17
Goal:
Create a configuration to obtain:
When you run the configuration are created:
- POJOs
- hmb.xml
- Change in hibernate.cfg.xml
- DAO object related to POJOs
Hibernate code generation configuration
22. Hibernate code generation configuration
21
New Configuration
General settings: use Java 5 syntax
Exporters: at least one file exporter
23. 22
Goal:
Create a configuration to obtain:
When you run the configuration are created:
- POJOs
- hmb.xml
- Change in hibernate.cfg.xml
- DAO object related to POJOs
Hibernate code generation configuration
24. Result: hibernate.reveng.xml
* This file match every table contained within the data base
* This file match just employee table contained within the data base
25. hibernate.reveng.xml
* This file match just employee table contained within the data base.
* The result has effect int the hibernate.cfg.xml changing the number of .hbm files.
Be careful:
27. 26
Goal:
Used the hibernate main files to retrieve and save object without SQL:
- POJOs
- hmb.xml
- DAO object related to POJOs
Retrieve objects List