SlideShare a Scribd company logo
1 of 13
Association and Association
and Collection Mapping
Association
– Mapping relationships between two objects
– Example
• Account and AccountOwner
Collection
–Collection of values representing individual pieces of data
– Example
• Map of holidays
• String array of months
Relationship Dimensions
Relationships between entities can
exist in multiple ways
– Multiplicity
• How many on each side of the
relationship?
– Directionality
A single object may have multiple A single object
may have multiple
relationships
Relationship Multiplicity
• One-to-Many
– A si l ng e A th ccount has many T ti ransactions
– Reverse of a many-to-one relationship
• Many-to-One
– Multiple Transactions belong to a single account
– Reverse of a one-to-many relationship
• One-to-One
– A single AccountOwner has a single HomeAddress
– A single HomeAddress has a single AccountOwner
• Many-to-Many
– Multiple Accounts have multiple AccountOwners
–Often realized through two one-to-many relationships
• A single Account has multiple AccountOwners
• A single AccountOwner has multiple Accounts
Relationship Directionality
• Unidirectional
–Can only traverse objects from one side of the
relationship
– Example: Account : Transaction
• Given an Account object, can obtain related
Transaction objects.
• Given a Transaction object, cannot obtain
related
Account object.
• Bidirectional
– Can traverse objects from both sides of the
relationship Can traverse objects from both
sides of the relationship
– Example: Account : Transaction
• Given an Account object, can obtain related
Transaction objects Transaction objects.
• Given a Transaction object, can obtain related
Account object.
Relationships in Java
• Object has an attribute referencing another related
Object
• For ‘Many’ side, Collections API
– Set
• No duplication allowed No duplication allowed
• Objects organized with or without order
– Map
• Duplicate values allowed using different keys Duplicate values allowed,
using different keys
• Can be organized with or without order
– List
• Duplication allowed Duplication allowed
• Objects expected to be organized in an order
– Arrays
• Duplication allowed
• Objects expected to be organized in an order
• Strongly typed to particular object type, and lacks ability to resize
Relationships in Database
• Record relationships can be realized using several
techniques
– Denormalized table
• Record repeated in same table each time capturing Record
repeated in same table, each time capturing different
relationship data.
– Foreign keys
• Follow identifiers to related records on other tables
– Join tables
• Tables sp yp p ecifically setup to maintain a relationship
between two identities (usually for M:M)
– Ad hoc joins in a query
• Arbitrary joins between columns relating data Arbitrary
joins between columns relating data
• Each technique has its pros/cons
Relationships in Database
• Denormalized Table
– Pros
• Very fast
• Easy to query against
– Cons
• Contains redundant data
• Requires many nullable columns
• Foreign Keys
– Pros
• Reduce redundancy
• Better modeling of data
– Cons
• Slower than denormalized table
• Slightly more complicated to query against
Domain object graph models
• Bidirectional relationships require graph model
updates for objects on both sides
– Need to keep all in-memory objects up-to-
date.
– If Objects A and B have a bidirectional
relationship, and Object B is added to Object A,
need to make sure that object A also gets
added to Object B
– Can cause complication when persisting the
relationship
• Which side should save the relationship?
• Hibernate represents domain object relationships
through a graph model relationships through a graph
model.
A B
C
E
F
D
Collections in Domain Objects
• Must always use Interfaces
–Collection, List, Map, Set, etc…
• Should be instantiated right away
Should be instantiated right away – Not delegated to
Constructor, Setter Method etc Method, etc…
List mylist = new ArrayList()
Mapping Multiplicity
• 1:M/M:1
– Example: EBiller has many EBills / EBill has one EBiller
– On the ‘one’ side, map the Collection objects (EBiller)
– On the ‘many’ side, map the single object (EBill)
• M:M
– Example: Account has many EBillers / EBiller has many
Accounts
– On both sides, map the Collection objects
• Only required on both sides if the relationship is
bidirectional
Java-to-Database Through
Hibernate
–<array>
• Map to Java Type and Primitive Arrays Map to Java
Type and Primitive Arrays • Ordered, requiring an
index column on the referenced object table
–<bag>
• No direct implementation available in Java
• Unordered/ordered collection allowing duplicates
Unordered/ordered collection allowing duplicates
• Realized through Collection/List
• Requires value column
–<idbag>
• Used for many-to-many relationships
• Same as Bag but with additional identifier Same as
Bag, but with additional identifier column used for
surrogate keys
• Requires an ID Generator just like Entity classes
Thank You
Vibrant Technology
Best trainingfor Hibernate in Mumbai,Navi
Mumbai

More Related Content

Similar to Best training hibernate_navi_mumbai

Data structure chapter 1.pptx
Data structure chapter 1.pptxData structure chapter 1.pptx
Data structure chapter 1.pptxKami503928
 
Database.ppt
Database.pptDatabase.ppt
Database.pptFaimHasan
 
DATA MODEL PRESENTATION UNIT I-BCA I.pptx
DATA MODEL PRESENTATION UNIT I-BCA I.pptxDATA MODEL PRESENTATION UNIT I-BCA I.pptx
DATA MODEL PRESENTATION UNIT I-BCA I.pptxJasmineMichael1
 
Learn Data Structures With Myassignmenthelp.Net
Learn Data Structures With Myassignmenthelp.NetLearn Data Structures With Myassignmenthelp.Net
Learn Data Structures With Myassignmenthelp.NetSteve Johnson
 
Asper database presentation - Data Modeling Topics
Asper database presentation - Data Modeling TopicsAsper database presentation - Data Modeling Topics
Asper database presentation - Data Modeling TopicsTerry Bunio
 
db design and maintenance part 1.pptx
db design and maintenance part 1.pptxdb design and maintenance part 1.pptx
db design and maintenance part 1.pptxahmadfaisal744721
 
Entityrelationshipmodel
EntityrelationshipmodelEntityrelationshipmodel
EntityrelationshipmodelEnes Bolfidan
 
Entity Relationship Model
Entity Relationship ModelEntity Relationship Model
Entity Relationship ModelSlideshare
 
data clean.ppt
data clean.pptdata clean.ppt
data clean.pptchatbot9
 
entityrelationshipmodel.pptx
entityrelationshipmodel.pptxentityrelationshipmodel.pptx
entityrelationshipmodel.pptxThangamaniR3
 
Dimensional modeling primer - SQL Saturday Madison - April 11th, 2015
Dimensional modeling primer - SQL Saturday Madison - April 11th, 2015Dimensional modeling primer - SQL Saturday Madison - April 11th, 2015
Dimensional modeling primer - SQL Saturday Madison - April 11th, 2015Terry Bunio
 

Similar to Best training hibernate_navi_mumbai (20)

relational database
relational databaserelational database
relational database
 
Data structure chapter 1.pptx
Data structure chapter 1.pptxData structure chapter 1.pptx
Data structure chapter 1.pptx
 
Data Visulalization
Data VisulalizationData Visulalization
Data Visulalization
 
Relational databases
Relational databasesRelational databases
Relational databases
 
Day 1 SQL.pptx
Day 1 SQL.pptxDay 1 SQL.pptx
Day 1 SQL.pptx
 
SQL.pptx
SQL.pptxSQL.pptx
SQL.pptx
 
Revision ch 3
Revision ch 3Revision ch 3
Revision ch 3
 
er-models.pptx
er-models.pptxer-models.pptx
er-models.pptx
 
Database.ppt
Database.pptDatabase.ppt
Database.ppt
 
DATA MODEL PRESENTATION UNIT I-BCA I.pptx
DATA MODEL PRESENTATION UNIT I-BCA I.pptxDATA MODEL PRESENTATION UNIT I-BCA I.pptx
DATA MODEL PRESENTATION UNIT I-BCA I.pptx
 
Learn Data Structures With Myassignmenthelp.Net
Learn Data Structures With Myassignmenthelp.NetLearn Data Structures With Myassignmenthelp.Net
Learn Data Structures With Myassignmenthelp.Net
 
Asper database presentation - Data Modeling Topics
Asper database presentation - Data Modeling TopicsAsper database presentation - Data Modeling Topics
Asper database presentation - Data Modeling Topics
 
db design and maintenance part 1.pptx
db design and maintenance part 1.pptxdb design and maintenance part 1.pptx
db design and maintenance part 1.pptx
 
Entityrelationshipmodel
EntityrelationshipmodelEntityrelationshipmodel
Entityrelationshipmodel
 
Entity Relationship Model
Entity Relationship ModelEntity Relationship Model
Entity Relationship Model
 
DATA MODELS.pptx
DATA MODELS.pptxDATA MODELS.pptx
DATA MODELS.pptx
 
data clean.ppt
data clean.pptdata clean.ppt
data clean.ppt
 
entityrelationshipmodel.pptx
entityrelationshipmodel.pptxentityrelationshipmodel.pptx
entityrelationshipmodel.pptx
 
Dimensional modeling primer - SQL Saturday Madison - April 11th, 2015
Dimensional modeling primer - SQL Saturday Madison - April 11th, 2015Dimensional modeling primer - SQL Saturday Madison - April 11th, 2015
Dimensional modeling primer - SQL Saturday Madison - April 11th, 2015
 
ds bridge.pptx
ds bridge.pptxds bridge.pptx
ds bridge.pptx
 

Recently uploaded

Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 

Recently uploaded (20)

Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 

Best training hibernate_navi_mumbai

  • 1. Association and Association and Collection Mapping
  • 2. Association – Mapping relationships between two objects – Example • Account and AccountOwner Collection –Collection of values representing individual pieces of data – Example • Map of holidays • String array of months
  • 3. Relationship Dimensions Relationships between entities can exist in multiple ways – Multiplicity • How many on each side of the relationship? – Directionality A single object may have multiple A single object may have multiple relationships
  • 4. Relationship Multiplicity • One-to-Many – A si l ng e A th ccount has many T ti ransactions – Reverse of a many-to-one relationship • Many-to-One – Multiple Transactions belong to a single account – Reverse of a one-to-many relationship • One-to-One – A single AccountOwner has a single HomeAddress – A single HomeAddress has a single AccountOwner • Many-to-Many – Multiple Accounts have multiple AccountOwners –Often realized through two one-to-many relationships • A single Account has multiple AccountOwners • A single AccountOwner has multiple Accounts
  • 5. Relationship Directionality • Unidirectional –Can only traverse objects from one side of the relationship – Example: Account : Transaction • Given an Account object, can obtain related Transaction objects. • Given a Transaction object, cannot obtain related Account object. • Bidirectional – Can traverse objects from both sides of the relationship Can traverse objects from both sides of the relationship – Example: Account : Transaction • Given an Account object, can obtain related Transaction objects Transaction objects. • Given a Transaction object, can obtain related Account object.
  • 6. Relationships in Java • Object has an attribute referencing another related Object • For ‘Many’ side, Collections API – Set • No duplication allowed No duplication allowed • Objects organized with or without order – Map • Duplicate values allowed using different keys Duplicate values allowed, using different keys • Can be organized with or without order – List • Duplication allowed Duplication allowed • Objects expected to be organized in an order – Arrays • Duplication allowed • Objects expected to be organized in an order • Strongly typed to particular object type, and lacks ability to resize
  • 7. Relationships in Database • Record relationships can be realized using several techniques – Denormalized table • Record repeated in same table each time capturing Record repeated in same table, each time capturing different relationship data. – Foreign keys • Follow identifiers to related records on other tables – Join tables • Tables sp yp p ecifically setup to maintain a relationship between two identities (usually for M:M) – Ad hoc joins in a query • Arbitrary joins between columns relating data Arbitrary joins between columns relating data • Each technique has its pros/cons
  • 8. Relationships in Database • Denormalized Table – Pros • Very fast • Easy to query against – Cons • Contains redundant data • Requires many nullable columns • Foreign Keys – Pros • Reduce redundancy • Better modeling of data – Cons • Slower than denormalized table • Slightly more complicated to query against
  • 9. Domain object graph models • Bidirectional relationships require graph model updates for objects on both sides – Need to keep all in-memory objects up-to- date. – If Objects A and B have a bidirectional relationship, and Object B is added to Object A, need to make sure that object A also gets added to Object B – Can cause complication when persisting the relationship • Which side should save the relationship? • Hibernate represents domain object relationships through a graph model relationships through a graph model. A B C E F D
  • 10. Collections in Domain Objects • Must always use Interfaces –Collection, List, Map, Set, etc… • Should be instantiated right away Should be instantiated right away – Not delegated to Constructor, Setter Method etc Method, etc… List mylist = new ArrayList()
  • 11. Mapping Multiplicity • 1:M/M:1 – Example: EBiller has many EBills / EBill has one EBiller – On the ‘one’ side, map the Collection objects (EBiller) – On the ‘many’ side, map the single object (EBill) • M:M – Example: Account has many EBillers / EBiller has many Accounts – On both sides, map the Collection objects • Only required on both sides if the relationship is bidirectional
  • 12. Java-to-Database Through Hibernate –<array> • Map to Java Type and Primitive Arrays Map to Java Type and Primitive Arrays • Ordered, requiring an index column on the referenced object table –<bag> • No direct implementation available in Java • Unordered/ordered collection allowing duplicates Unordered/ordered collection allowing duplicates • Realized through Collection/List • Requires value column –<idbag> • Used for many-to-many relationships • Same as Bag but with additional identifier Same as Bag, but with additional identifier column used for surrogate keys • Requires an ID Generator just like Entity classes
  • 13. Thank You Vibrant Technology Best trainingfor Hibernate in Mumbai,Navi Mumbai