hibernate reverse engineering
TRANSCRIPT
Contents 1
1. Hibernate view
2. Create a “new hibernate configuration”
3. Hibernate Reverse Engineering: hibernate.reveng.xml
4. Hibernate code generation configuration
5. Reverse engineering
6. Retrieve objects List
7. Example using Session.get
Create a “new hibernate configuration” 5
Goal:
connect Eclipse with the Data Base using a Hibernate bridge
Eclipse Hibernate
Hibernate.cfg.xml
Data Base
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
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)
Create a “new hibernate configuration” 9
Classpath Tab Classpath: you must include hibernate libraries into the path
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)
Hibernate Reverse Engineering: hibernate.reveng.xml 13
File > New > Hibernate Reverse Engineering File (reveng.xml)
Hibernate Reverse Engineering: hibernate.reveng.xml 14
Parent Folder: must be selected the project folder
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
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
Hibernate code generation configuration 19
New Configuration Console configuration: the same name configured in step 1
Hibernate code generation configuration 21
New Configuration General settings: use Java 5 syntax Exporters: at least one file exporter
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
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
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:
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
27
Method used: getEmployeeExample
- First of all we need to configure a Session Factory in order to obtain a Session
Retrieve objects List
28
We obtain a list of objects, though a casting those are converted to Employees
Retrieve objects List
29
We obtain one object and though a casting is converted into an Employee
Example using Session.get
30 Example using Session.get
We obtain one object and though a casting is converted into an Employee