Advanced DatabaseUnit 312 min read
Enhanced ER Model: Specialization, Generalization, Aggregation & ODMG
Unit 3 of Advanced Database explores the Enhanced Entity-Relationship (EER) model, covering specialization/generalization hierarchies (disjoint/overlapping, total/partial), aggregation, and ODMG object model. It includes real-world mappings, query examples, and exam-focused comparisons with traditional ER.
TAKEAWAYS:
- EER extends ER with specialization (IS-A), generalization (subtype/supertype), and aggregation (HAS-A) to model complex real-world hierarchies.
- Specialization constraints (disjoint/overlapping, total/partial) define how entities share attributes and relationships.
- ODMG Object Model integrates OO concepts (classes, inheritance) into databases, with OQL for querying.
- Aggregation vs. Generalization: Aggregation groups entities (e.g.,
DepartmentHAS-AProfessor), while generalization creates IS-A hierarchies (e.g.,VehicleIS-ACar). - EER-to-relational mapping requires careful handling of discriminators, inheritance, and composite attributes.
- Real-world applications include eSewa’s user hierarchies (e.g.,
CustomerIS-APremiumCustomer) and NTC’s network aggregation (e.g.,RegionHAS-AExchange).
Core Concepts of EER Model
The Enhanced Entity-Relationship (EER) model builds on the classic ER model by adding:
- Specialization/Generalization (IS-A hierarchies)
- Aggregation (HAS-A relationships)
- Categories (entities that can belong to multiple supertypes)
- Attributes inheritance (shared and unique attributes in hierarchies).
Unlike ER, EER explicitly models semantic constraints (e.g., whether a subtype must belong to a supertype or can belong to multiple).
1. Specialization and Generalization
Generalization is a bottom-up process: combining entities with common attributes into a supertype (e.g., Animal → Mammal, Bird).
Specialization is top-down: splitting a supertype into subtypes (e.g., Vehicle → Car, Bike).
Key Constraints
| Constraint | Definition | Example |
|---|---|---|
| Disjoint | An entity can belong to only one subtype. | Employee → Manager/Worker (no overlap). |
| Overlapping | An entity can belong to multiple subtypes. | Student → Scholar/Athlete (a student can be both). |
| Total | All supertype entities must belong to at least one subtype. | Person → Student/Employee (every Person is one or the other). |
| Partial | Subtypes are optional; supertype entities may not belong to any. | Customer → PremiumCustomer (not all customers are premium). |
Worked Example: NTC’s Network Hierarchy Nepal Telecom’s (NTC) network can be modeled with specialization:
- Supertype:
NetworkNode- Subtypes (disjoint, total):
Exchange(handles routing)BaseStation(handles mobile signals)DataCenter(handles cloud services)
- Subtypes (disjoint, total):
- Attributes:
NetworkNode:nodeID,locationExchange:capacity,connectedRegionsBaseStation:frequency,coverageArea
Why? This lets NTC query all nodes uniformly (e.g., SELECT * FROM NetworkNode) while optimizing for each subtype’s needs (e.g., SELECT * FROM Exchange WHERE capacity > 1000).
2. Aggregation
Aggregation models a "HAS-A" relationship where one entity is composed of others (e.g., a Department HAS-A Professor). Unlike generalization (IS-A), aggregation is structural, not hierarchical.
Aggregation vs. Generalization
| Feature | Aggregation (HAS-A) | Generalization (IS-A) |
|---|---|---|
| Relationship | Whole-part (e.g., Car HAS-A Engine) |
Hierarchy (e.g., Car IS-A Vehicle) |
| Inheritance | No attribute inheritance | Subtypes inherit supertype attributes |
| Example | University HAS-A Department |
Department IS-A AcademicUnit |
| ER Representation | Diamond (◇) between entities | Triangle (△) for specialization |
Worked Example: eSewa’s User Aggregation eSewa’s system aggregates users into groups:
- Supertype:
User- Aggregated Entities:
UserHAS-ATransactionHistoryUserHAS-ASubscriptionPlan(e.g.,Basic,Premium)
- Aggregated Entities:
- Why? This lets eSewa:
- Query all transactions for a user:
SELECT * FROM TransactionHistory WHERE userID = 123. - Apply discounts based on
SubscriptionPlan:IF plan.type = 'Premium' THEN discount = 0.1.
- Query all transactions for a user:
3. ODMG Object Model
The Object Data Management Group (ODMG) standard integrates object-oriented (OO) concepts into databases:
- Objects: Encapsulate data (attributes) + behavior (methods).
- Classes: Blueprints for objects (e.g.,
Accountclass withbalanceattribute anddeposit()method). - Inheritance: Supports IS-A hierarchies (e.g.,
SavingsAccountinherits fromAccount). - Object Query Language (OQL): SQL-like syntax for querying objects.
ODMG vs. Relational Model
| Feature | ODMG Object Model | Relational Model |
|---|---|---|
| Data Model | Objects with methods | Tables with rows/columns |
| Query Language | OQL (e.g., SELECT a.deposit(1000) FROM Account a) |
SQL (e.g., UPDATE Account SET balance = balance + 1000) |
| Inheritance | Native support (e.g., SavingsAccount extends Account) |
Requires manual mapping (e.g., UNION types) |
| Example | Bank database with Account classes |
Bank database with Accounts table |
classDiagram
class Account {
+String accountNumber
+double balance
+deposit(amount)
+withdraw(amount)
}
class SavingsAccount {
+double interestRate
+calculateInterest()
}
class CurrentAccount {
+double overdraftLimit
}
Account <|-- SavingsAccount : extends
Account <|-- CurrentAccount : extends
class Bank {
+List~Account~ accounts
}
Bank "1" *-- "0..*" Account : contains
caption ODMG inheritance hierarchy with Bank-Account relationshipWorked Example: Ncell’s Billing System Ncell’s billing system uses ODMG-like objects:
- Superclass:
Customer- Subclasses:
PrepaidCustomer(methods:topUp(),checkBalance())PostpaidCustomer(methods:payBill(),checkDueDate())
- Subclasses:
- Query: Find all prepaid customers with balance < 100:
SELECT c FROM PrepaidCustomer c WHERE c.balance < 100 - Why? This avoids redundant code (e.g.,
checkBalance()is shared) and enables polymorphic queries.
4. EER to Relational Mapping
Converting EER to relational schema requires handling:
- Specialization: Use a discriminator attribute (e.g.,
type) or separate tables with foreign keys. - Aggregation: Represent as foreign keys or separate tables.
- Inheritance: Map to single-table (all attributes in one table) or multiple-table (one table per subtype) inheritance.
Mapping Rules
| EER Concept | Relational Mapping | Example |
|---|---|---|
| Disjoint Total | Single table with discriminator column | Employee(empID, name, type, managerID) where type is Manager/Worker. |
| Overlapping | Separate tables + intersection table | Student(studentID), Scholar(scholarID), Athlete(athleteID), StudentScholar(studentID, scholarID). |
| Aggregation | Foreign key or separate table | Department(deptID), Professor(profID, deptID) (foreign key). |
| Generalization | Single-table or class-table inheritance | Single-table: Vehicle(vehicleID, type, wheels). Class-table: Vehicle(vehicleID), Car(carID, vehicleID). |
Worked Example: Daraz Order Processing Daraz’s order system uses specialization for order types:
- Supertype:
Order- Subtypes (disjoint, total):
StandardOrder(attributes:shippingCost)ExpressOrder(attributes:deliveryTime)
- Subtypes (disjoint, total):
- Relational Schema:
CREATE TABLE Order ( orderID INT PRIMARY KEY, customerID INT, orderDate DATE, type VARCHAR(20) -- Discriminator ); CREATE TABLE StandardOrder ( orderID INT PRIMARY KEY, shippingCost DECIMAL, FOREIGN KEY (orderID) REFERENCES Order(orderID) ); CREATE TABLE ExpressOrder ( orderID INT PRIMARY KEY, deliveryTime INT, -- Hours FOREIGN KEY (orderID) REFERENCES Order(orderID) ); - Query: Find all express orders delivered in < 24 hours:
SELECT * FROM ExpressOrder WHERE deliveryTime < 24;
In the Real World
eSewa’s User Hierarchy
- Concept: Specialization (disjoint, total).
- How? eSewa models users as:
User(supertype:userID,name,email)- Subtypes:
IndividualUser,BusinessUser(disjoint: a user is one or the other).
- Why? Enables role-based access control (e.g.,
BusinessUsercan register merchants).
NTC’s Network Aggregation
- Concept: Aggregation (HAS-A).
- How? NTC’s network is modeled as:
RegionHAS-AExchangeHAS-ABaseStation.
- Why? Simplifies queries like "Find all base stations in Kathmandu" by traversing the aggregation hierarchy.
Nepal Rastra Bank’s Loan System
- Concept: ODMG-like inheritance.
- How? Loan types are modeled as:
Loan(superclass:loanID,amount,interestRate)- Subclasses:
PersonalLoan,BusinessLoan,HomeLoan(each with unique attributes/methods).
- Why? Enables polymorphic operations like
calculateEMI()tailored to each loan type.
Exam Tip
- Diagrams are Mandatory
- Always draw EER diagrams for design questions. Label:
- Specialization with △ and constraints (disjoint/overlapping, total/partial).
- Aggregation with ◇.
- Example: For a library system, show
MemberIS-AStudentMember/FacultyMember(disjoint, total) andLibraryHAS-ABranch(aggregation).
- Always draw EER diagrams for design questions. Label:
Mapping is High-Weightage
- For EER-to-relational questions:
- Identify specialization constraints first.
- Use discriminator columns for disjoint total hierarchies.
- Use separate tables + intersection tables for overlapping subtypes.
- Example: A
Vehiclehierarchy withCar/Bike(disjoint, total) maps to:Vehicle(vehicleID, type, wheels) Car(carID, vehicleID, model) Bike(bikeID, vehicleID, gearCount)
- For EER-to-relational questions:
ODMG and OQL Tricks
- Define ODMG’s three-layer architecture (application, object database, storage) in exams.
- For OQL questions, emphasize:
- Polymorphic queries:
SELECT o FROM Order o WHERE o.type = 'Express'. - Method invocation:
SELECT a.deposit(500) FROM Account a.
- Polymorphic queries:
Common Pitfalls
- Confusing aggregation with generalization: Aggregation is structural (e.g.,
DepartmentHAS-AProfessor), while generalization is hierarchical (e.g.,ProfessorIS-AFaculty). - Forgetting discriminators: In disjoint total specialization, always include a
typecolumn or use separate tables. - Overlapping subtypes: Require an intersection table (e.g.,
StudentScholarfor overlappingStudent/Scholar).
- Confusing aggregation with generalization: Aggregation is structural (e.g.,
Based on the TU BSc CSIT syllabus for Advanced Database (CSC461), unit 3.
Discussion
Loading…