Search code examples
database-designentity-relationshipobject-role-modeling

Weak entities: how to express in ORM?


In entity-relationship diagrams there's a weak entity type, which is an entity that has no key attribute. I would like to know what the object-role modelling equivalent is.


Solution

  • Your definition of weak entity type is incorrect. In ER, every entity type must have a primary key in any case. A weak entity type has a mandatory foreign key in its own primary key.

    It's same in ORM, but even more general. An entity type which contains any mandatory role may only exist if the corresponding role is filled, so it is dependent on the existence of a role player. It is irrelevant whether that role is played by another entity type, or whether the object type playing that role gets mapped to another table. It is also irrelevant whether the mandatory role is part of any identifier (including the preferred identifier) though that's the situation where the description "weak" is likely to be used. However, the idea of "weak" is unnecessary to ORM and should not be used.

    Note an ET is not the same thing as an ER entity, and not all ETs will necessarily be mapped to a table.