Pattern: Objects in BLOBs

Abstract

The pattern demonstrates a way to map objects to a single database table using BLOBs. The pattern covers inheritance, aggregation, and associations. It is interesting from an academic point of view and as a source of ideas to solve unusual problems in mapping objects to relational databases.

Problem

How do you map objects to a relational database?

Forces

The forces are identical to those discussed with the One Inheritance Tree One Table pattern.

Solution

Use a table containing two fields: One for the synthetic OID and a second one for a variable length BLOB that contains all the data an object holds. Use streaming to unload the object’s data to the BLOB.

Structure

Example Resolved

The table design for our running example or any other example looks exactly like the above table design.

Consequences

Implementation

Figure 3: Coexistence of Object Data and Relational Data (picture adapted from [Rei+94])

Related Patterns

Used in a pure form, the pattern is similar to the One Inheritance Tree One Table mapping. See also Representing Inheritance in a Relational Database [Bro+96].

Fowler calls this the Serialized LOB pattern on his site.