mapping objects relational db n.
Download
Skip this Video
Loading SlideShow in 5 Seconds..
Mapping Objects ↔ Relational DB PowerPoint Presentation
Download Presentation
Mapping Objects ↔ Relational DB

Loading in 2 Seconds...

play fullscreen
1 / 21

Mapping Objects ↔ Relational DB - PowerPoint PPT Presentation


  • 92 Views
  • Uploaded on

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.

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

Mapping Objects ↔ Relational DB


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
the problem with databases
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
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 db1
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
    • Aone-to-many association is implemented as buried foreign key
  • Methods are not mapped
how to map
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
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 ↔ tables ?
  • Classes maps to tables (often not directly)
  • No one-to-one mapping of classes to tables (exceptions exists)
implementing inheritance
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
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
Using one data entity per concreteclass
  • 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
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)
mapping associations aggregation and composition
Mapping associations , aggregation, and composition
  • Relationship between objects must also be mapped.
  • These relationship may be :
      • Inheritance
      • Association
      • Aggregation
      • composition
implementing one to one relationship
Implementingone-to-onerelationship
  • 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
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
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

*

Airport Table

Serves Table

City Table

airportCode

IAH

HOU

ALB

MUC

HAM

airportCode

IAH

HOU

ALB

MUC

HAM

cityName

Houston

Houston

Albany

Munich

Hamburg

airportName

Intercontinental

Hobby

Albany County

Munich Airport

Hamburg Airport

cityName

Houston

Albany

Munich

Hamburg

Mapping Many-To-Many Associations

In this case we need a separate table for the association

Separate table for

“Serves” association

Primary Key