I'm using the concept of single table inheritance
because of OOP considerations of course.
for example, PostLike
and TopicLike
inherit from Like
class.
I see two problems with this methodology:
I'm not a DB expert and because of that I wanted to get your insights about this database design and whether or not those two problems are crucial.
If you have only one table instead of two, the reads will be faster, because you'll avoid "joins". But you'll use more space because you'll have an extra "dtype" column, and some empty columns.
Let's get an example. Here is the model (without the JPA annotations):
public abstract class Like {
public Long id;
public String foo;
}
public class PostLike extends Like {
public String post;
}
public class TopicLike extends Like {
public String topic;
}
You'll get the table Like
:
----------------------------------
|dtype | id | foo | topic | post |
----------------------------------
|post | 1 | a | NULL | p1 |
|topic | 2 | b | t1 | NULL |
----------------------------------
And as you can see, for a "PostLike" item, you'll have a NULL "topic" value.
But nowadays, the disk space if not a real problem.
The only flaw I see with single table inheritance is the number of columns which can be huge if you have a lot of properties, and it is harder to add a new property/column in your model (if you have to apply a DB evolution).
And AFAIK, ebean only supports "single table inheritance".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With