Showing posts with label Serialized LOB. Show all posts
Showing posts with label Serialized LOB. Show all posts

Saturday, 10 August 2013

Serialized LOB Design Pattern

🚀 Master Enterprise Java & Architecture Patterns!

Subscribe to Ram N Java for clean, simple, and beginner-friendly programming tutorials!

🔔 Subscribe Now

What is the Serialized LOB Design Pattern?

The Serialized LOB Pattern is an important Object-Relational Structural Pattern from Martin Fowler's classic enterprise book, Patterns of Enterprise Application Architecture (PofEAA).

Core Definition: The pattern saves a graph of objects by serializing them into a single Large Object (LOB) which it stores directly in a database field.

A LOB can be a BLOB (Binary Large Object), a CLOB (Character Large Object), or structured text formats like JSON or XML.

The Problem: Storing Complex Hierarchies in Relational Tables

Consider an organizational tree structure:

  • CEO (John): Oversees two department heads: Rob and Peter.
  • Rob: Manages two sales executives: Julie and Mark.
  • Peter: Manages two clerks: David and Steve.

Mapping this deep hierarchical tree into a standard relational database requires parent-child tables with recursive foreign keys. Querying and updating deep object graphs requires multiple nested SQL JOIN operations, which degrades performance and creates complex database manipulation logic.

The Solution: Serialize the Object Graph into a LOB

Instead of decomposing an object graph across several relational tables, you serialize the entire in-memory object hierarchy into a single formatted payload (such as JSON, XML, or binary data) and store it in one database column:

CREATE TABLE organization_unit (
    unit_id BIGINT PRIMARY KEY,
    unit_name VARCHAR(100),
    department_graph CLOB  -- Serialized LOB column storing the complete tree
);

When reading the data, your application retrieves that single field and deserializes it back into an active, connected graph of objects in memory with a single read operation.

Advantages & Trade-offs

  • Zero Recursive JOINs: Fetching complex object graphs requires only a single database query row.
  • Simplified Persistence: Adding new fields or nodes to the graph does not require altering the database schema.
  • Query Limitations: You generally cannot query individual fields inside a serialized LOB using standard relational SQL (unless using native JSON functions).
  • Best Used For: Object graphs that are always retrieved, modified, and saved together as a single cohesive unit.

Recommended Design Pattern Tutorials:


Click here to watch in Youtube : https://www.youtube.com/watch?v=NnT1iZuSlR4

Click the below Image to Enlarge
Serialized LOB Design Pattern















See also:

  • All Design Patterns Links
  • Tutorials