Note that there are some explanatory texts on larger screens.

plurals
  1. POHibernate: table per concrete class vs. table per subclass
    text
    copied!<p>I'm planing / designing my database for my current project (Java). For this project I'm going to use hibernate.</p> <p>In my project I have a base class/interface called Command. In fact the Command class contains only a field id (unique).</p> <pre><code>public interface Command { public int getId(); public void execute(); } </code></pre> <p>So what every subclass of Command has in common is an unique id and a method called execute, which is implemented by the subclasses.</p> <p>There exists many sub classes like MoveCommand, ResizeCommand etc. which has no common data fields (except the id).</p> <p>For example:</p> <pre><code>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() { ... } } </code></pre> <p>Then I have another class called Document, which contains a list of commands</p> <pre><code>public class Document { private List&lt;Command&gt; commands; } </code></pre> <p>So a lot of queries of the base class "select from Command" were executed on runtime.</p> <p>My question is: What kind of inheritance strategy should I use in this case to get the best performance.</p> <p>In SQL: does JOIN (table per subclass ) or UNION (table per concrete class) perform better in this case?</p> <p>Does anyone has experience with this topic?</p> <p>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. </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload