Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 146113
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T08:32:38+00:00 2026-05-11T08:32:38+00:00

Folks, For the n-th time in a row, i’m hitting the same old problem

  • 0

Folks,

For the n-th time in a row, i’m hitting the same old problem again. It’s about ‘how do I map OOP structures to database tables in a painless way.’

Here’s a scenario: I have several types of ‘actors’ in my system – workers, employers, contacts. They have certain pieces of functionality in common; other pieces are vastly different. The entities that all actors deal with are ‘communications’, ‘notes’ (admins like to leave notes on customers), and a few more. There are tons of types of other entities that each actor type deals with, while the others don’t.

Currently, my database schema includes tables for:

Actors:

  • worker
  • employer
  • contact

Entities:

  • communication
  • notes
  • etc.

Association tables between entities and actors:

  • worker-communication-assn
  • employer-communication-assn
  • worker-notes-assn
  • etc, you get the drill.

This feels like a ‘code smell’ to me. Whenever a customer changes their role (i.e. promoted from ‘contact’ to ’employer’), a bunch of crazy scripts need to be run. Yuck… On the other hand, if i was operating in a purely OOP-driven world, this would be much easier – have a base class for all entities with common properties, and be done with it…

In the DB world, that option seems theoretically possible, but sounds very messy… I.e. if I understand this right, I’d have a new base_actor table, and each other actor would have a base_actor_id, and then the associations would be between base_actor and the entities… But then, how do I do reverse-association queries? I.e. ‘show me all communications with just actors of type worker’?

Any advice? Any general thoughts on the subject of ‘mapping OOP structures to relational DB’?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T08:32:38+00:00Added an answer on May 11, 2026 at 8:32 am

    Here’s a solution I came up with about 10 years ago. The system that uses this design is still running, so it worked well enough to survive longer than most of my code. 😉 Today I may use one of the ORM packages that Scott mentions, but there’s really no huge problems just using SQL directly.

    1. Model all of your inheritance relations as joins between tables. Each table in your system will hold the attributes of a specific class.

    2. Use a synthetic object id (oid) as your primary key for all objects. A sequence generator or autoincrement column is necessary to generate oid values.

    3. All inherited classes must use the same oid type as their parent. Define the oid as a foreign key with cascaded delete. The parent table gets the autoincrement oid column and the children get plain oid columns.

    4. Queries on final classes are made on the corresponding table. You can either join all the parent class tables into the query or just lazy load the attributes you need. If your inheritance hierarchy is deep and you have many classes, an ORM package can really simplify your code. My system had less than 50 classes with a maximum inheritance depth of 3.

    5. Queries across child classes (i.e. queries on a parent class) can either lazy load the child attributes on a per-instance basis, or you can repeat the query for each child class joined with base classes. Lazy loading child attributes based on a parent class query requires you know the type of the object. You may have enough information in the parent classes already, but if not you’ll need to add type information. Again, this is where an ORM package can help.

    Virtual classes without member attributes can be skipped in the table structure, but you won’t be able to query based on those classes.

    Here’s what ‘show me all communications with just actors of type worker’ looks like.

    select * from comm c, worker w where c.actor=w.oid; 

    If you have sub-classes of communication, and you want to immediately load all the child class attributes (perhaps your system does not allow partial construction), the easiest solution is to eager join on all the possible classes.

    select * from comm c, worker w, missive m where c.actor=w.oid and c.oid=m.oid; select * from comm c, worker w, shoutout s where c.actor=w.oid and c.oid=s.oid; 

    One last thing. Make sure you have a good database and correct indexes. Performance can be a serious problem if you database can’t optimize these joins.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 82k
  • Answers 82k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer First check if the class is correcty deployed. See also… May 11, 2026 at 4:39 pm
  • Editorial Team
    Editorial Team added an answer I think as Lazarus that you should stay with what… May 11, 2026 at 4:39 pm
  • Editorial Team
    Editorial Team added an answer Seriously, you should leave them where they are. Applications will… May 11, 2026 at 4:39 pm

Related Questions

Folks, For the n-th time in a row, i'm hitting the same old problem
In a WPF page that I'm designing for my church, I have two ListBox
I was just interviewed with a question, and I'm curious what the answer ought
Folks, I have some HTML generated from my WSDL and XSD files for a
I'm looking for the fastest way to obtain the value of π, as a

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.