Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Yes, there are other approaches. Basically, you have a Member entity, and this entity has two subclasses: StudentMember and StaffMember. The StaffMember has an association with a Staff, and the StudentMamber has an association with a Student.</p> <p>This inheritance can be mapped in three different ways.</p> <ol> <li><p>everything in a single table. This would lead to your first database design: the user_role column is the discriminator column, and either student_id or staff_id is null.</p></li> <li><p>Each concrete class has its own table. This would lead to two identical tables, except one would have a student_id column and one would have a staff_id column.</p></li> <li><p>Each class has its own table. This would lead to 3 tables: one (member) which would contain all the common columns (id, banned, group_id, etc.), one which would contain only the StudentMember specific columns (the ID, referencing the member table, and the student ID), and one which would contain the StaffMember specific columns (the ID, referencing the member table, and the staff ID).</p></li> </ol> <p>All the approaches have pros and cons: </p> <ul> <li>the first one leads to nullable join columns, but is very efficient (no need for joins to load all the members of a group, for example). It's also impossible for another table to have a FK to a StudentMember, but only to a Member.</li> <li>the second one leads to column duplications, and needs joins to load members (but no join to load StudentMember or StaffMember), but it has no nullable foreign keys, and it's possible to have a FK to a StaffMember or a StudentMember, but not to any Member.</li> <li>the third one is inefficient, because it needs joins for every query. But it has no column duplication, and you can have foreign keys to whatever you want.</li> </ul> <p>Given that you onlyhave one column which differs between the sub-entities, I would go for the first solution, which is easier to understand, query and optimize, and leads to much simpler queries.</p> <p>All these inheritance strategies are described in <a href="http://docs.jboss.org/hibernate/core/3.6/reference/en-US/html_single/#inheritance-strategies" rel="nofollow">the documentation</a>.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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