7.1. Object Relational Mismatch

This section of the chapter walks through a simple example and brings to light a few of the common differences between the object world and the relational world.

Let's assume that your application keeps records for the employees of a company. Each employee is a person who has a few attributes such as name, ID, role, manager's name, and contact information. Each person's contact information could include his or her email, phone, fax, and instant messaging ID.

For starters, let's create the database schema and the object model for the "employee" entity and its associated information. The first problem that you will immediately encounter is that of granularity.

7.1.1. Coarse-Grained or Fine-Grained

Following object-oriented principles, you may end up creating three objects, namely Employee, ContactInfo, and Role, with definitions like this:

public class Employee
{
    private int employeeId;
    private String name;
    private Set roles;
    private String managerName;
    private ContactInfo contactInfo;

    //accessor methods

}

public class ContactInfo
{

    private String email;
    private String phone;
    private String fax;
    private String im;

    //accessor methods

}

public class Role
{
    Private int roleId;
    private String description;
    private String businessUnit;

    //accessor methods

}

On the other hand, you will create two tables to keep the relational schema optimized. The Data Description Language (DDL) statements for the two table creation operations are like so:

create table employees ...

Get Professional BlazeDS: Creating Rich Internet Applications with Flex® and Java® now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.