Mapping Objects ↔Relational DB. The Problem with Databases Databases store data in rows in tables, which are not like objects. We can simulate object.

Slides:



Advertisements
Similar presentations
BUSINESS DRIVEN TECHNOLOGY Plug-In T4 Designing Database Applications.
Advertisements

Data Design The futureERD - CardinalityCODINGRelationshipsDefinition.
Slides adapted from A. Silberschatz et al. Database System Concepts, 5th Ed. Database Management Systems I Alex Coman, Winter 2006 Entity-Relationship.
Concepts of Database Management Sixth Edition
Concepts of Database Management Sixth Edition
Data Management Design
Designing a Database Unleashing the Power of Relational Database Design.
Chapter 11 Data Management Layer Design
Database Design Chapter 2. Goal of all Information Systems  To add value –Reduce costs –Increase sales or revenue –Provide a competitive advantage.
Concepts of Database Management Seventh Edition
©Silberschatz, Korth and Sudarshan2.1Database System Concepts Reduction of an E-R Schema to Tables A database which conforms to an E-R diagram can be represented.
APPENDIX C DESIGNING DATABASES
 Keys are special fields that serve two main purposes: ◦ Primary keys are unique identifiers of the relation in question. Examples include employee numbers,
The Entity-Relationship Model. 421B: Database Systems - ER Model 2 Overview of Database Design q Conceptual Design -- A first model of the real world.
Ch5: ER Diagrams - Part 2 Much of the material presented in these slides was developed by Dr. Ramon Lawrence at the University of Iowa.
Chapter 3 The Relational Model and Normalization
UML Unified Modeling Language. What is UML? Unified Modeling Language (UML) is a standardized, general-purpose modeling language in the field of software.
Database Design Concepts
Data Access Patterns Some of the problems with data access from OO programs: 1.Data source and OO program use different data modelling concepts 2.Decoupling.
1 Chapter 1 Overview of Database Concepts. 2 Chapter Objectives Identify the purpose of a database management system (DBMS) Distinguish a field from a.
1 ER Modeling BUAD/American University Entity Relationship (ER) Modeling.
Concepts and Terminology Introduction to Database.
Conquering Complex and Changing Systems Object-Oriented Software Engineering Chapter 6, System Design Lecture 2.
RELATIONSHIPS Generally there are two main database types: flat-file and relational.
ECE 8443 – Pattern Recognition ECE 3822 – Software Tools For Engineers Topics: Definitions and Terminology Abstraction Schema Tables Types of Databases.
Systems Analysis and Design in a Changing World, 6th Edition 1 Chapter 4 - Domain Classes.
Chapter 3: Relational Model  Structure of Relational Databases  Normal forms (chap. 7)  Reduction of an E-R Schema to Relational (Sect. 2.9)  Relational.
Lecture2: Database Environment Prepared by L. Nouf Almujally & Aisha AlArfaj 1 Ref. Chapter2 College of Computer and Information Sciences - Information.
1 A Guide to MySQL 2 Database Design Fundamentals.
Systems Analysis and Design in a Changing World, 6th Edition 1 Chapter 4 Domain Classes.
Chapter 12: Designing Databases
Concepts of Database Management Sixth Edition Chapter 6 Database Design 2: Design Method.
Chapter 1Introduction to Oracle9i: SQL1 Chapter 1 Overview of Database Concepts.
Unit 3 Conceptual Data Modeling. Key Concepts Conceptual data modeling process Classes and objects Attributes Identifiers, candidate keys, and primary.
EXAMPLE. Subclasses and Superclasses Entity type may have sub-grouping that need to be represented explicitly. –Example: Employee may grouped into.
1 Session 2 Welcome: The seventh learning sequence “ Reduction of an EER schema to tables“ Recap : In the previous learning sequence, we discussed the.
DataBase Management System What is DBMS Purpose of DBMS Data Abstraction Data Definition Language Data Manipulation Language Data Models Data Keys Relationships.
Conquering Complex and Changing Systems Object-Oriented Software Engineering Chapter 6, System Design Lecture 2.
Prepared by Jennifer Kreie, New Mexico State UniversityHosted by the University of Arkansas Microsoft Enterprise Consortium Database Fundamentals Physical.
1 © Prentice Hall, 2002 Chapter 5: Logical Database Design and the Relational Model Modern Database Management 6 th Edition Jeffrey A. Hoffer, Mary B.
Concepts of Database Management, Fifth Edition Chapter 6: Database Design 2: Design Methodology.
Jozef Kuper.  Describe a Database  Entities  Atributes  Relationships.
Burapha University, 2003 Object-Oriented Analysis Basic of Object Mapping to Relational Database.
ICOM 5016 – Introduction to Database Systems Lecture 9 Dr. Manuel Rodriguez Department of Electrical and Computer Engineering University of Puerto Rico,
Entity Relationship Diagram (2)
In this session, you will learn to: Map an ER diagram to a table Objectives.
ENTITY RELATIONSHIP DIAGRAM ENTITY RELATIONSHIP DIAGRAM IS A SPECIALIZED GRAPHIC THAT ILLUSTRATES THE INTERRELATIONSHIPS BETWEEN ENTITIES IN A DATABASE.
Topic : Hibernate 3:Advanced ORM Kaster Nurmukan.
Relational Theory and Design
Using UML, Patterns, and Java Object-Oriented Software Engineering Chapter 10, Mapping Models to Relational Schema.
Seminar 10: OODB Design (Self-Study)
BSA206 Database Management Systems Lecture 2: Introduction to Oracle / Overview of Database Concepts.
Falak Nawaz Mapping Models to Code. Object Model activities 1. Reuse: Identification of existing solutions  Use of inheritance  Off-the-shelf components.
1 DATABASE TECHNOLOGIES (Part 2) BUS Abdou Illia, Fall 2015 (September 9, 2015)
Copyright © 2013 by The McGraw-Hill Companies, Inc. All rights reserved. McGraw-Hill/Irwin APPENDIX C DESIGNING DATABASES APPENDIX C DESIGNING DATABASES.
1 ER Modeling BUAD/American University Mapping ER modeling to Relationships.
March 1, 2004CS WPI1 CS 509 Design of Software Systems Lecture #6 Monday, March 1, 2004.
Understand Relational Database Management Systems Software Development Fundamentals LESSON 6.1.
V 1.0 DBMAN 9 Inheritance Modeling + Relational Databases 1.
FEN Mapping from Class Diagram (Domain Model) to Relational Model Table Design.
IST 220 – Intro to DB Lecture 4 Database Design thru ER Modeling.
1 10 Systems Analysis and Design in a Changing World, 2 nd Edition, Satzinger, Jackson, & Burd Chapter 10 Designing Databases.
Data Modeling AND ER MODELS.
Microsoft Access CS 110 Fall Entity Relationship Model Entities Entities Principal data object about which information is to be collectedPrincipal.
Lecture # 14 Chapter # 5 The Relational Data Model and Relational Database Constraints Database Systems.
XP Chapter 1 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach 1 Level 2 Objectives: Understanding and Creating Table.
State of the Art: Model-based Software Engineering
Chapter 10, Mapping Models to Relational Schema
Revised: 2 April 2004 Fred Swartz
Chapter 10, Mapping Models to Relational Schema
Presentation transcript:

Mapping Objects ↔Relational DB

The Problem with Databases Databases store data in rows in tables, which are not like objects. We can simulate object associations and collections using relations between rows in tables. Preserving uniqueness of objects and some object properties using persistence is difficult. Some conceptual differences exist, referred to as the Object-Relational Paradigm Mismatch

Mapping an object model to a relational DB UML object models can be mapped to relational databases:  Some degradation occurs because all UML constructs must be mapped to a single relational database construct - the table.

Mapping an object model to a relational DB UML mappings  Each class is mapped to a table  Each class attribute is mapped onto a column in the table  An instance of a class represents a row in the table  A many-to-many association is mapped into its own table  A one-to-many association is implemented as buried foreign key Methods are not mapped

How to map ? Mapping attributes ↔ columns Impelmenting inheritance in a relational database Mapping classes ↔ tables Mapping associations, aggregation, and composition Implementing relationships in relational database

attributes ↔ columns ? Class attribute ↔ Zero or a number of columns in DB Zero : Not all attributes are persistent grantTotal ( no need for storage in DB) Many columns : Object having objects as attributtes Customer object having an instance of ” address”. Address will map to many columns ( number, street, floor..etc) Several attributes ↔ single column US zip code with 3 numeric attributes will be stored as a single column.

classes ↔ tables ? Classes maps to tables (often not directly) No one-to-one mapping of classes to tables (exceptions exists)

Implementing Inheritance ? Three fundamental solutions for mapping inheritance into a relational database Using one data entity for an entire class hierarchy Using one data entity per concrete class Using one data entity per class

Using one data entity for an entire class hierarchy Map the entire class hierarchy into one data entity, where the attributes of all the classes in the hierarchy are stored ObjectType column is added to indicate whether the row represents a student, a professor Disadvantages : the person is both a student and a professor

Using one data entity per concrete class Each data entity includes both the attributes and the inherited attributes of the class that itv represents Advantages : Easy to perform Disavantages : A lot of work when you modify a class (ex : adding height and weight to Person) If change in role, copy data into appropriate table and assign new OID Difficult to support multiple roles ( where to store the name of someone who is both a student and a professor)

Using one data entity per class One table per class Advantages : Conform best to object-oriented concepts Easy to modify superclasses and add new subclasses Disadvantages Many tables in DB Longer to read and write data (you access many tables)

Comparison

Mapping associations, aggregation, and composition Relationship between objects must also be mapped. These relationship may be : Inheritance Association Aggregation composition

Do you remember !!!

Impelementing relationships

Implementing one-to-one relationship Relationship are maintained through the use of foreign keys. One-to-one relationship : include the key of one table in the other table.  Position and Employee data entities  Include the attribute ”positionOID”, the key of Position data entity,in the ”Employee” data entity. Why ?

Implementing many–to-one relationship Many-to-one relationship : Put the foreign key in the ”many”side of the relation  Task and Employee data entities

Implementing many –to-many relationship Many-to-one relationship : Introduce an associative table, a new data entity Many to many between Benefit and Employee data entities Name of the associative entity is a combination of the names of the tables that is it associates

Mapping Many-To-Many Associations City cityName Airport airportCode airportName * * Serves cityName Houston Albany Munich Hamburg City Table airportCode IAH HOU ALB MUC HAM Airport Table airportName Intercontinental Hobby Albany County Munich Airport Hamburg Airport Primary Key cityName Houston Albany Munich Hamburg Serves Table airportCode IAH HOU ALB MUC HAM In this case we need a separate table for the association Separate table for “Serves” association

Thanks for your attention Questions ?