hibernate reverse engineering

Download Hibernate   reverse engineering

Post on 18-Jul-2015

108 views

Category:

Technology

1 download

Embed Size (px)

TRANSCRIPT

  • Hibernate reverse engineering

    Jos Luis Muoz

    Jun 17, 2012

  • 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

  • Hibernate view 2

    Choose the correct view Window > Show View > Hibernate configurations

  • Hibernate view 3

    Click on Hibernate

  • Hibernate view 4

    Click on Open Perspective; this open a dialog box

  • 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 8

    Options Tab Database dialect: MySQL

  • Create a new hibernate configuration 9

    Classpath Tab Classpath: you must include hibernate libraries into the path

  • Create a new hibernate configuration 10

    Result

  • Hibernate Reverse Engineering: hibernate.reveng.xml 11

  • 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

  • Result 16

    * This file specified the tables contained within the data base which must be mapped

  • 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 18

    Run option

  • Hibernate code generation configuration 19

    New Configuration Console configuration: the same name configured in step 1

  • Hibernate code generation configuration 20

    New Configuration Revenge.xml: the file generated before

  • 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:

  • hibernate.reveng.xml

    * This file match the schema

    * NO RESULTS

    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

  • The End 31

    joseluis@trustparency.es

    Hibernatereverse engineeringContentsHibernate viewHibernate viewHibernate viewCreate a new hibernate configurationCreate a new hibernate configurationCreate a new hibernate configurationCreate a new hibernate configurationCreate a new hibernate configurationCreate a new hibernate configurationHibernate Reverse Engineering: hibernate.reveng.xmlHibernate Reverse Engineering: hibernate.reveng.xmlHibernate Reverse Engineering: hibernate.reveng.xmlHibernate Reverse Engineering: hibernate.reveng.xmlHibernate Reverse Engineering: hibernate.reveng.xmlResultHibernate code generation configurationHibernate code generation configurationHibernate code generation configurationHibernate code generation configurationHibernate code generation configurationHibernate code generation configurationResult: hibernate.reveng.xmlhibernate.reveng.xmlhibernate.reveng.xmlRetrieve objects ListRetrieve objects ListRetrieve objects ListExample using Session.getExample using Session.getThe End