Reputation: 631
I'm designing database tables for the hierarchy as shown in the image below. There are no recursive dependencies, and hence fixed levels. Only the presence of Group1 is hindering the design. In the hierarchy, only Item4 and Item5 have parent as Group1, rest all Items have System as its parents.
Request for your feedback & suggestions.
I've designed tables as follows:
Site Table - SiteId (PK)
System Table - SystemId (PK), SiteId(FK)
Item Table - ItemId(PK), SystemId(FK)
Group Table - GroupId(PK), ItemId(FK)
In the above design, I intend to use transitive property to identify Item4 and Item5 belong to Group1.
Is this design good? or have any suggestions? Also request for query suggestions in Hibernate.
Upvotes: 1
Views: 262
Reputation: 153950
Since Item
and Group
are on the same level and being associated to the same System
, I would use inheritance to map their relationship:
So you can have an AbstractItem
base class which is extended by both Item
and Group
, but only Group
has also a one-to-many
association to an Item
.
The System many-to-one association can reside in AbstractItem
. A JOIN
inheritance model is probably better for your use case than SINGLE_TABLE
.
Upvotes: 1