SlideShare une entreprise Scribd logo
1  sur  16
Télécharger pour lire hors ligne
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

Contenu connexe

Tendances

Layout discovery. Drupal Summer Barcelona 2017
Layout discovery. Drupal Summer Barcelona 2017Layout discovery. Drupal Summer Barcelona 2017
Layout discovery. Drupal Summer Barcelona 2017Atenea tech
 
jQuery UI Widgets, Drag and Drop, Drupal 7 Javascript
jQuery UI Widgets, Drag and Drop, Drupal 7 JavascriptjQuery UI Widgets, Drag and Drop, Drupal 7 Javascript
jQuery UI Widgets, Drag and Drop, Drupal 7 JavascriptDarren Mothersele
 
Drupal Step-by-Step: How We Built Our Training Site, Part 1
Drupal Step-by-Step: How We Built Our Training Site, Part 1Drupal Step-by-Step: How We Built Our Training Site, Part 1
Drupal Step-by-Step: How We Built Our Training Site, Part 1Acquia
 
WooCommerce CRUD and Data Store by Akeda Bagus
WooCommerce CRUD and Data Store by Akeda BagusWooCommerce CRUD and Data Store by Akeda Bagus
WooCommerce CRUD and Data Store by Akeda BagusWordCamp Indonesia
 
Top Ten Reasons to Use EntityFieldQuery in Drupal
Top Ten Reasons to Use EntityFieldQuery in DrupalTop Ten Reasons to Use EntityFieldQuery in Drupal
Top Ten Reasons to Use EntityFieldQuery in DrupalFredric Mitchell
 
Introduction to hibernate
Introduction to hibernateIntroduction to hibernate
Introduction to hibernatehr1383
 
Drupal II: The SQL
Drupal II: The SQLDrupal II: The SQL
Drupal II: The SQLddiers
 
Apache Con Us2007 Apachei Batis
Apache Con Us2007 Apachei BatisApache Con Us2007 Apachei Batis
Apache Con Us2007 Apachei Batisday
 
Intro To Hibernate
Intro To HibernateIntro To Hibernate
Intro To HibernateAmit Himani
 
Dig Deeper into WordPress - WD Meetup Cairo
Dig Deeper into WordPress - WD Meetup CairoDig Deeper into WordPress - WD Meetup Cairo
Dig Deeper into WordPress - WD Meetup CairoMohamed Mosaad
 
Drupal & javascript
Drupal & javascriptDrupal & javascript
Drupal & javascriptAlmog Baku
 
WordPress Capabilities Magic
WordPress Capabilities MagicWordPress Capabilities Magic
WordPress Capabilities Magicmannieschumpert
 
Ajax nested form and ajax upload in rails
Ajax nested form and ajax upload in railsAjax nested form and ajax upload in rails
Ajax nested form and ajax upload in railsTse-Ching Ho
 
Drupal Development (Part 2)
Drupal Development (Part 2)Drupal Development (Part 2)
Drupal Development (Part 2)Jeff Eaton
 
Propel sfugmd
Propel sfugmdPropel sfugmd
Propel sfugmdiKlaus
 
Drupal - dbtng 25th Anniversary Edition
Drupal - dbtng 25th Anniversary EditionDrupal - dbtng 25th Anniversary Edition
Drupal - dbtng 25th Anniversary Editionddiers
 

Tendances (19)

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

En vedette

حقه علينا للشيخ احمد الدبوس
حقه علينا   للشيخ احمد الدبوسحقه علينا   للشيخ احمد الدبوس
حقه علينا للشيخ احمد الدبوسمحمد سحنون
 
بور بوينت منظمة الشفيع
بور بوينت منظمة الشفيعبور بوينت منظمة الشفيع
بور بوينت منظمة الشفيعمحمد سحنون
 
Analysis of defaults in real world variability models
Analysis of defaults in real world variability modelsAnalysis of defaults in real world variability models
Analysis of defaults in real world variability modelsLeonardo Passos
 
Feature-Oriented Software Evolution
Feature-Oriented Software EvolutionFeature-Oriented Software Evolution
Feature-Oriented Software EvolutionLeonardo Passos
 
الشيخ احمد الدبوس - النموذج القرآني
 الشيخ احمد الدبوس - النموذج القرآني الشيخ احمد الدبوس - النموذج القرآني
الشيخ احمد الدبوس - النموذج القرآنيمحمد سحنون
 
Affiliate marketing biblija_1
Affiliate marketing biblija_1Affiliate marketing biblija_1
Affiliate marketing biblija_1Make Money Online
 
مقاصد القرآن الكريم
مقاصد القرآن الكريممقاصد القرآن الكريم
مقاصد القرآن الكريممحمد سحنون
 

En vedette (13)

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

Similaire à Hibernate

Doctrine 2
Doctrine 2Doctrine 2
Doctrine 2zfconfua
 
Drupal 8: Entities
Drupal 8: EntitiesDrupal 8: Entities
Drupal 8: Entitiesdrubb
 
Mapping Classes with Relational Databases
Mapping Classes with Relational DatabasesMapping Classes with Relational Databases
Mapping Classes with Relational DatabasesAathikaJava
 
Doctrine MongoDB Object Document Mapper
Doctrine MongoDB Object Document MapperDoctrine MongoDB Object Document Mapper
Doctrine MongoDB Object Document MapperJonathan Wage
 
Desarrollo de módulos en Drupal e integración con dispositivos móviles
Desarrollo de módulos en Drupal e integración con dispositivos móvilesDesarrollo de módulos en Drupal e integración con dispositivos móviles
Desarrollo de módulos en Drupal e integración con dispositivos móvilesLuis Curo Salvatierra
 
Opencast Admin UI - Introduction to developing using AngularJS
Opencast Admin UI - Introduction to developing using AngularJSOpencast Admin UI - Introduction to developing using AngularJS
Opencast Admin UI - Introduction to developing using AngularJSbuttyx
 
Contagion的Ruby/Rails投影片
Contagion的Ruby/Rails投影片Contagion的Ruby/Rails投影片
Contagion的Ruby/Rails投影片cfc
 
jQuery and Rails: Best Friends Forever
jQuery and Rails: Best Friends ForeverjQuery and Rails: Best Friends Forever
jQuery and Rails: Best Friends Foreverstephskardal
 
Tutorial: Develop an App with the Odoo Framework
Tutorial: Develop an App with the Odoo FrameworkTutorial: Develop an App with the Odoo Framework
Tutorial: Develop an App with the Odoo FrameworkOdoo
 
Your Entity, Your Code
Your Entity, Your CodeYour Entity, Your Code
Your Entity, Your CodeDrupalDay
 
From mysql to MongoDB(MongoDB2011北京交流会)
From mysql to MongoDB(MongoDB2011北京交流会)From mysql to MongoDB(MongoDB2011北京交流会)
From mysql to MongoDB(MongoDB2011北京交流会)Night Sailer
 
Fernando F. Gallego - Efficient Android Resources 101
Fernando F. Gallego - Efficient Android Resources 101Fernando F. Gallego - Efficient Android Resources 101
Fernando F. Gallego - Efficient Android Resources 101Fernando Gallego
 
Intro to MongoDB and datamodeling
Intro to MongoDB and datamodeling Intro to MongoDB and datamodeling
Intro to MongoDB and datamodeling rogerbodamer
 
Modularity and Layered Data Model
Modularity and Layered Data ModelModularity and Layered Data Model
Modularity and Layered Data ModelAttila Jenei
 
Web applications with Catalyst
Web applications with CatalystWeb applications with Catalyst
Web applications with Catalystsvilen.ivanov
 
Active Record Inheritance in Rails
Active Record Inheritance in RailsActive Record Inheritance in Rails
Active Record Inheritance in RailsSandip Ransing
 

Similaire à Hibernate (20)

Doctrine 2
Doctrine 2Doctrine 2
Doctrine 2
 
Drupal 8: Entities
Drupal 8: EntitiesDrupal 8: Entities
Drupal 8: Entities
 
Mapping Classes with Relational Databases
Mapping Classes with Relational DatabasesMapping Classes with Relational Databases
Mapping Classes with Relational Databases
 
Doctrine MongoDB Object Document Mapper
Doctrine MongoDB Object Document MapperDoctrine MongoDB Object Document Mapper
Doctrine MongoDB Object Document Mapper
 
Hibernate
HibernateHibernate
Hibernate
 
Drupal 8 migrate!
Drupal 8 migrate!Drupal 8 migrate!
Drupal 8 migrate!
 
Desarrollo de módulos en Drupal e integración con dispositivos móviles
Desarrollo de módulos en Drupal e integración con dispositivos móvilesDesarrollo de módulos en Drupal e integración con dispositivos móviles
Desarrollo de módulos en Drupal e integración con dispositivos móviles
 
Opencast Admin UI - Introduction to developing using AngularJS
Opencast Admin UI - Introduction to developing using AngularJSOpencast Admin UI - Introduction to developing using AngularJS
Opencast Admin UI - Introduction to developing using AngularJS
 
Broadleaf Presents Thymeleaf
Broadleaf Presents ThymeleafBroadleaf Presents Thymeleaf
Broadleaf Presents Thymeleaf
 
Contagion的Ruby/Rails投影片
Contagion的Ruby/Rails投影片Contagion的Ruby/Rails投影片
Contagion的Ruby/Rails投影片
 
jQuery and Rails: Best Friends Forever
jQuery and Rails: Best Friends ForeverjQuery and Rails: Best Friends Forever
jQuery and Rails: Best Friends Forever
 
Tutorial: Develop an App with the Odoo Framework
Tutorial: Develop an App with the Odoo FrameworkTutorial: Develop an App with the Odoo Framework
Tutorial: Develop an App with the Odoo Framework
 
Your Entity, Your Code
Your Entity, Your CodeYour Entity, Your Code
Your Entity, Your Code
 
Css Selectors
Css SelectorsCss Selectors
Css Selectors
 
From mysql to MongoDB(MongoDB2011北京交流会)
From mysql to MongoDB(MongoDB2011北京交流会)From mysql to MongoDB(MongoDB2011北京交流会)
From mysql to MongoDB(MongoDB2011北京交流会)
 
Fernando F. Gallego - Efficient Android Resources 101
Fernando F. Gallego - Efficient Android Resources 101Fernando F. Gallego - Efficient Android Resources 101
Fernando F. Gallego - Efficient Android Resources 101
 
Intro to MongoDB and datamodeling
Intro to MongoDB and datamodeling Intro to MongoDB and datamodeling
Intro to MongoDB and datamodeling
 
Modularity and Layered Data Model
Modularity and Layered Data ModelModularity and Layered Data Model
Modularity and Layered Data Model
 
Web applications with Catalyst
Web applications with CatalystWeb applications with Catalyst
Web applications with Catalyst
 
Active Record Inheritance in Rails
Active Record Inheritance in RailsActive Record Inheritance in Rails
Active Record Inheritance in Rails
 

Dernier

Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Victor Rentea
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistandanishmna97
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...apidays
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Victor Rentea
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDropbox
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024The Digital Insurer
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKJago de Vreede
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsNanddeep Nachan
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024The Digital Insurer
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...apidays
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Zilliz
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native ApplicationsWSO2
 

Dernier (20)

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 

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