Chapter 12 Creating Mappings


Object to Relational (O/R) mapping

Developers tend to use object-oriented programming languages like Java, to develop business objects and components. These objects can be stored in a database. A problem arises when the user tries to store objects in a relational database because object modeling describes a system through objects that have identity, behavior and encapsulated state whereas relational modeling describes a system by its data.

Furthermore, object codes in an OOM for a given object language are often different than codes used in a relational database. This requires that you modify object codes after generating an OOM into a PDM or a PDM into an OOM to be compliant with the object language.

You can use object mapping to bypass this impedance-mismatch.

The following schema illustrates the link between classes and tables to store objects in a relational database:


Object persistence implies to store and extract objects in a relational database.

Mapping classes with PDM objects

When a class inherits from a non-generated class via a generalization link, the attributes of the class appear in the Selection dialog box in order to let you create a mapping with these inherited attributes. The attributes of a non-generated derived class also appear in the Selection dialog box.

Mapping associations with PDM objects

O/R mapping on an association allows you to define the role navigability of an association in the database. When an association role is not navigable, there is no need to design a mapping for the association since no information is transmitted between the classes. However, when an association role is navigable, you have to set up the structure for data transmission within the database. In relational databases, data transmission is implemented via foreign keys designed to relate a record in one table with a record in another.

The type of mapping for an association depends on the association multiplicity:

SQL queries

When the association roles are navigable, the following queries are automatically computed:

Query Action
Select (Role A) Retrieves related class A instances for the role A defined on class B
Insert (Role A) Associates an instance of class A with class B. It is computed only when the source association is an associative table
Delete (Role A) Deletes from class B the association with class A. This query is computed only when the source association is an associative table
Select (Role B) Retrieves related class B instances for the role B defined on class A
Insert (Role B) Associates an instance of class B with class A. This query is computed only when the source association is an associative table
Delete (Role B) Deletes from class A the association with class B. This query is computed only when the source association is an associative table

 


Copyright (C) 2008. Sybase Inc. All rights reserved.