SlideShare a Scribd company logo
MDE using Hibernate ORM

           Leonardo Passos
     (lpassos@gsd.uwaterloo.ca)




                                  1
Object Relational Mapping (ORM)




                                  2
ORM library in Java




                      3
What is a mapping?
        <hibernate-mapping>
         <class name="sample.Person" table="person">
           <id name="id">
             <generator class="native"/>
           </id>
           <property name="name" type="string" not-null="true"/>
           <property name="phoneNumber" type="string" not-null="true"/>
           <property name="email" type="string" not-null="true"/>
         </class>
        </hibernate-mapping>


●   Hibernate's MDE support:
    ●   Generation of corresponding DDL scripts
    ●   Generation of Java POJOs


                                                                          4
Associations
●   One to one

●   One to many

●   Many to many

●   Unidirectional/Bidirectional




                                          5
Some examples...




                   6
Unidirectional one to one association


<hibernate-mapping>
 <class name="sample.Person" table="person">
   <id name="id">
    <generator class="native"/>
   </id>
   <property name="name" type="string" not-null="true"/>
   <property name="phoneNumber" column=”phone_number” type="string" not-null="true"/>
   <property name="email" type="string" not-null="true"/>

   <many-to-one name="address"
                class="Address"                     Needs mapping definition
                column="address_id"
                cascade="save-update"
                unique="true"/>
 </class>
</hibernate-mapping>



                                                                                   7
                                                  Solution: foreign key association
Unidirectional one to one association




<hibernate-mapping>
 <class name="sample.Address" table="address">
  <id name="id">
    <generator class="native"/>
  </id>
  <property name="street" type="string" not-null="true"/>
  <property name="zipcode" type="string" not-null="true"/>
  <!-- other properties of interest... -->
 </class>
</hibernate-mapping>




                                                             8
Unidirectional one to one association (stronger)


<hibernate-mapping>
 <class name="sample.Person" table="person">
   <id name="id">
    <generator class="native"/>
   </id>
   <property name="name" type="string" not-null="true"/>
   <property name="phoneNumber" column=”phone_number” type="string" not-null="true"/>
   <property name="email" type="string" not-null="true"/>

   <many-to-one name="address" class="Address"
           column="address_id"
           cascade="all"
           unique="true"/>
 </class>
</hibernate-mapping>




                                                                                   9
Bidirectional one to one association
●   Person defined as before, but Address now contains


         <hibernate-mapping>
          <class name="sample.Address" table="address">
           <id name="id">
             <generator class="native"/>
           </id>
           <property name="street" type="string" not-null="true"/>
           <property name="zipcode" type="string" not-null="true"/>
           <!-- other properties of interest... -->

            <one-to-one name="person"
                        class="sample.Person"
                        property-ref="address"/>
          </class>
         </hibernate-mapping>



                                                                      10
Bidirectional one to one association
                      (alternative solution)
<hibernate-mapping>
 <class name="sample.Person" table="person">
   <id name="id">
     <generator class="native"/>
   </id>
   <!-- properties... -->
   <one-to-one name="address" class="sample.Address" cascade="all" />
 </class>
</hibernate-mapping>



<hibernate-mapping>
 <class name="sample.Address" table="address">
  <id name="id">
    <generator class="foreign">
      <param name=”property”> person </param>
  </id>
  <!-- properties... -->
  <one-to-one name=”person” class=”sample.Person” constrained=”true”/>
 </class>
                                                                              11
</hibernate-mapping>
                                                  Solution: primary key association
Bidirectional many to many association
●   Suppose two classes: Category and Item
    ●   A bidirectional association from Category to Item ('*' on both ends)
         –   In RDB, one needs to use an intermediate table to connect category and item
             (e.g.: category_item)



              <hibernate-mapping>
               <class name="sample.Category" table="category">
                 ...
                 <set name="items" table="category_item"                     1
                     lazy="true"
                     cascade="save-update"/>
                     <key column="category_id"/>
                     <many-to-many class="Item" column="item_id"/>
                </set>
               </class>
              </hibernate-mapping>

                                                                                      12
Bidirectional many to many association
●   Suppose two classes: Category and Item
    ●   A bidirectional association from Category to Item ('*' on both ends)
         –   In RDB, one needs to use an intermediate table to connect category and item
             (e.g.: category_item)



              <hibernate-mapping>
               <class name="sample.Item" table="item">
                 ...
                 <set name="categories" table="category_item"                2
                     lazy="true"
                     cascade="save-update
                     inverse=”true”"/>
                     <key column="item_id"/>
                     <many-to-many class="Category" column="category_id"/>
                </set>
               </class>
              </hibernate-mapping>
                                                                                      13
Conclusions




              14
Conclusions
●   The semantics of associations are defined as part of the
    mapping specification
    ●   Users give the semantics they need
●   Models are written in a declarative-fashion using XML
●   MDE Support:
    ●   DDL generation
    ●   POJO generation




                                                               15
Questions


            16

More Related Content

PPTX
Hibernate inheritance and relational mappings with examples
PDF
Drupal Entities - Emerging Patterns of Usage
PDF
Aug 3-2012 - StiltSoft - 10 features for JIRA admin
PPTX
Drupal 7 entities & TextbookMadness.com
PDF
Entities in drupal 7
ODP
Entity Query API
PPTX
Build your own entity with Drupal
PDF
Simplifying JavaScript Projects with ReactJS
Hibernate inheritance and relational mappings with examples
Drupal Entities - Emerging Patterns of Usage
Aug 3-2012 - StiltSoft - 10 features for JIRA admin
Drupal 7 entities & TextbookMadness.com
Entities in drupal 7
Entity Query API
Build your own entity with Drupal
Simplifying JavaScript Projects with ReactJS

What's hot (19)

PPTX
Layout discovery. Drupal Summer Barcelona 2017
PDF
jQuery UI Widgets, Drag and Drop, Drupal 7 Javascript
PDF
Drupal Step-by-Step: How We Built Our Training Site, Part 1
PDF
WooCommerce CRUD and Data Store by Akeda Bagus
PDF
Top Ten Reasons to Use EntityFieldQuery in Drupal
PPT
Introduction to hibernate
PPTX
Drupal II: The SQL
PDF
Apache Con Us2007 Apachei Batis
 
PPTX
Service Oriented Architecture-Unit-1-XML Schema
PPT
Intro To Hibernate
PDF
Dig Deeper into WordPress - WD Meetup Cairo
PDF
Drupal & javascript
PDF
WordPress Capabilities Magic
PDF
Ajax nested form and ajax upload in rails
ZIP
Drupal Development (Part 2)
PDF
RequireJS & Handlebars
PDF
Your Entity, Your Code
PPT
Propel sfugmd
PDF
Drupal - dbtng 25th Anniversary Edition
Layout discovery. Drupal Summer Barcelona 2017
jQuery UI Widgets, Drag and Drop, Drupal 7 Javascript
Drupal Step-by-Step: How We Built Our Training Site, Part 1
WooCommerce CRUD and Data Store by Akeda Bagus
Top Ten Reasons to Use EntityFieldQuery in Drupal
Introduction to hibernate
Drupal II: The SQL
Apache Con Us2007 Apachei Batis
 
Service Oriented Architecture-Unit-1-XML Schema
Intro To Hibernate
Dig Deeper into WordPress - WD Meetup Cairo
Drupal & javascript
WordPress Capabilities Magic
Ajax nested form and ajax upload in rails
Drupal Development (Part 2)
RequireJS & Handlebars
Your Entity, Your Code
Propel sfugmd
Drupal - dbtng 25th Anniversary Edition
Ad

Viewers also liked (13)

PDF
حقه علينا للشيخ احمد الدبوس
PPTX
بور بوينت منظمة الشفيع
PDF
PDF
Analysis of defaults in real world variability models
PDF
Feature-Oriented Software Evolution
DOC
PTC Sajtovi - Opis
PDF
صور الأضاحي
DOC
RIBE JADRANA U ISHRANI
PDF
FOSD Presentation
PDF
الشيخ احمد الدبوس - النموذج القرآني
PDF
Affiliate marketing biblija_1
PDF
SPLC Presentation
PDF
مقاصد القرآن الكريم
حقه علينا للشيخ احمد الدبوس
بور بوينت منظمة الشفيع
Analysis of defaults in real world variability models
Feature-Oriented Software Evolution
PTC Sajtovi - Opis
صور الأضاحي
RIBE JADRANA U ISHRANI
FOSD Presentation
الشيخ احمد الدبوس - النموذج القرآني
Affiliate marketing biblija_1
SPLC Presentation
مقاصد القرآن الكريم
Ad

Similar to Hibernate (20)

PDF
Hibernate Mapping
PDF
Hibernate Mapping
PPTX
HIBERNATE For Databases java presentation.pptx
DOC
Hibernate Online Training
PDF
PDF
APPLY HIBERNATE TO MODEL AND PERSIST ASSOCIATIONS MAPPINGS IN DOCUMENT VERSIO...
PDF
Apply hibernate to model and persist associations mappings in document versio...
PDF
Hibernate using jpa
ODP
Java Persistence API
PPT
Spring data
PDF
Kick Start Jpa
PDF
PPT
Patni Hibernate
PDF
JPA and Hibernate
PPTX
Hibernate
PPT
Persisting Your Objects In The Database World @ AlphaCSP Professional OSS Con...
PPTX
New-Hibernate-introduction cloud cc.pptx
PPT
En webinar jpa v2final
PDF
Using the latest Java Persistence API 2 Features - Tech Days 2010 India
PDF
hibernate
Hibernate Mapping
Hibernate Mapping
HIBERNATE For Databases java presentation.pptx
Hibernate Online Training
APPLY HIBERNATE TO MODEL AND PERSIST ASSOCIATIONS MAPPINGS IN DOCUMENT VERSIO...
Apply hibernate to model and persist associations mappings in document versio...
Hibernate using jpa
Java Persistence API
Spring data
Kick Start Jpa
Patni Hibernate
JPA and Hibernate
Hibernate
Persisting Your Objects In The Database World @ AlphaCSP Professional OSS Con...
New-Hibernate-introduction cloud cc.pptx
En webinar jpa v2final
Using the latest Java Persistence API 2 Features - Tech Days 2010 India
hibernate

Recently uploaded (20)

PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PPTX
Spectroscopy.pptx food analysis technology
PDF
Approach and Philosophy of On baking technology
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
KodekX | Application Modernization Development
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
Machine learning based COVID-19 study performance prediction
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
cuic standard and advanced reporting.pdf
PPTX
Programs and apps: productivity, graphics, security and other tools
PPTX
Big Data Technologies - Introduction.pptx
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PPTX
Cloud computing and distributed systems.
Unlocking AI with Model Context Protocol (MCP)
Encapsulation_ Review paper, used for researhc scholars
Advanced methodologies resolving dimensionality complications for autism neur...
Spectroscopy.pptx food analysis technology
Approach and Philosophy of On baking technology
Dropbox Q2 2025 Financial Results & Investor Presentation
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
KodekX | Application Modernization Development
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Diabetes mellitus diagnosis method based random forest with bat algorithm
The Rise and Fall of 3GPP – Time for a Sabbatical?
The AUB Centre for AI in Media Proposal.docx
Machine learning based COVID-19 study performance prediction
“AI and Expert System Decision Support & Business Intelligence Systems”
MIND Revenue Release Quarter 2 2025 Press Release
cuic standard and advanced reporting.pdf
Programs and apps: productivity, graphics, security and other tools
Big Data Technologies - Introduction.pptx
Per capita expenditure prediction using model stacking based on satellite ima...
Cloud computing and distributed systems.

Hibernate

  • 1. MDE using Hibernate ORM Leonardo Passos (lpassos@gsd.uwaterloo.ca) 1
  • 3. ORM library in Java 3
  • 4. What is a mapping? <hibernate-mapping> <class name="sample.Person" table="person"> <id name="id"> <generator class="native"/> </id> <property name="name" type="string" not-null="true"/> <property name="phoneNumber" type="string" not-null="true"/> <property name="email" type="string" not-null="true"/> </class> </hibernate-mapping> ● Hibernate's MDE support: ● Generation of corresponding DDL scripts ● Generation of Java POJOs 4
  • 5. Associations ● One to one ● One to many ● Many to many ● Unidirectional/Bidirectional 5
  • 7. Unidirectional one to one association <hibernate-mapping> <class name="sample.Person" table="person"> <id name="id"> <generator class="native"/> </id> <property name="name" type="string" not-null="true"/> <property name="phoneNumber" column=”phone_number” type="string" not-null="true"/> <property name="email" type="string" not-null="true"/> <many-to-one name="address" class="Address" Needs mapping definition column="address_id" cascade="save-update" unique="true"/> </class> </hibernate-mapping> 7 Solution: foreign key association
  • 8. Unidirectional one to one association <hibernate-mapping> <class name="sample.Address" table="address"> <id name="id"> <generator class="native"/> </id> <property name="street" type="string" not-null="true"/> <property name="zipcode" type="string" not-null="true"/> <!-- other properties of interest... --> </class> </hibernate-mapping> 8
  • 9. Unidirectional one to one association (stronger) <hibernate-mapping> <class name="sample.Person" table="person"> <id name="id"> <generator class="native"/> </id> <property name="name" type="string" not-null="true"/> <property name="phoneNumber" column=”phone_number” type="string" not-null="true"/> <property name="email" type="string" not-null="true"/> <many-to-one name="address" class="Address" column="address_id" cascade="all" unique="true"/> </class> </hibernate-mapping> 9
  • 10. Bidirectional one to one association ● Person defined as before, but Address now contains <hibernate-mapping> <class name="sample.Address" table="address"> <id name="id"> <generator class="native"/> </id> <property name="street" type="string" not-null="true"/> <property name="zipcode" type="string" not-null="true"/> <!-- other properties of interest... --> <one-to-one name="person" class="sample.Person" property-ref="address"/> </class> </hibernate-mapping> 10
  • 11. Bidirectional one to one association (alternative solution) <hibernate-mapping> <class name="sample.Person" table="person"> <id name="id"> <generator class="native"/> </id> <!-- properties... --> <one-to-one name="address" class="sample.Address" cascade="all" /> </class> </hibernate-mapping> <hibernate-mapping> <class name="sample.Address" table="address"> <id name="id"> <generator class="foreign"> <param name=”property”> person </param> </id> <!-- properties... --> <one-to-one name=”person” class=”sample.Person” constrained=”true”/> </class> 11 </hibernate-mapping> Solution: primary key association
  • 12. Bidirectional many to many association ● Suppose two classes: Category and Item ● A bidirectional association from Category to Item ('*' on both ends) – In RDB, one needs to use an intermediate table to connect category and item (e.g.: category_item) <hibernate-mapping> <class name="sample.Category" table="category"> ... <set name="items" table="category_item" 1 lazy="true" cascade="save-update"/> <key column="category_id"/> <many-to-many class="Item" column="item_id"/> </set> </class> </hibernate-mapping> 12
  • 13. Bidirectional many to many association ● Suppose two classes: Category and Item ● A bidirectional association from Category to Item ('*' on both ends) – In RDB, one needs to use an intermediate table to connect category and item (e.g.: category_item) <hibernate-mapping> <class name="sample.Item" table="item"> ... <set name="categories" table="category_item" 2 lazy="true" cascade="save-update inverse=”true”"/> <key column="item_id"/> <many-to-many class="Category" column="category_id"/> </set> </class> </hibernate-mapping> 13
  • 15. Conclusions ● The semantics of associations are defined as part of the mapping specification ● Users give the semantics they need ● Models are written in a declarative-fashion using XML ● MDE Support: ● DDL generation ● POJO generation 15
  • 16. Questions 16