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

  • SEARCH
  • Home
  • 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 6751495
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T12:56:03+00:00 2026-05-26T12:56:03+00:00

I’m planing / designing my database for my current project (Java). For this project

  • 0

I’m planing / designing my database for my current project (Java). For this project I’m going to use hibernate.

In my project I have a base class/interface called Command. In fact the Command class contains only a field id (unique).

public interface Command {
   public int getId();
   public void execute();
}

So what every subclass of Command has in common is an unique id and a method called execute, which is implemented by the subclasses.

There exists many sub classes like MoveCommand, ResizeCommand etc. which has no common data fields (except the id).

For example:

public class MoveCommand implements Command {
   private int id;
   private int oldX;
   private int oldY;
   private int newX;
   private int newY;
   public void execute() { ... }
   public int getId(){return id; }
}

public class ResizeCommand implements Command {
   private int id;
   private int oldWidth;
   private int oldHeight;
   private int newWidth;
   private int newHeight;
   public int getId(){return id; }
   public void execute() { ... }
}

Then I have another class called Document, which contains a list of commands

public class Document {
  private List<Command> commands;
}

So a lot of queries of the base class “select from Command” were executed on runtime.

My question is:
What kind of inheritance strategy should I use in this case to get the best performance.

In SQL: does JOIN (table per subclass ) or UNION (table per concrete class) perform better in this case?

Does anyone has experience with this topic?

I guess table per subclass would be the better (design) solution, but I’m not sure about it, since there would exist a database table with a single column (id), because that’s the only thing that commands have in common.

  • 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. Editorial Team
    Editorial Team
    2026-05-26T12:56:03+00:00Added an answer on May 26, 2026 at 12:56 pm

    I would expect the union strategy to be faster, because it needs less joins, but it really depends on what your application does. Since the base table doesn’t contain any other column than the ID, it’s not really useful anyway.

    The differences between both aproaches are mainly related to normalization. The join strategy allows defining foreign keys to any class in the hierarchy (even the base class), whereas the union strategy only allows foreign keys to the concrete classes. This might be an issue for your join table between document and command. The union strategy also implies duplication of the common columns, but you don’t have any in your case, so it’s not really an issue.

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

Sidebar

Related Questions

this is what i have right now Drawing an RSS feed into the php,
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have some data like this: 1 2 3 4 5 9 2 6
I have thousands of HTML files to process using Groovy/Java and I need to
I have a reasonable size flat file database of text documents mostly saved in
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is

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.