Discussion on Semantics

Documents Home

Database Design Convention (Recommendation)

Topic Discussion / Recommendation
Primary Key
No compond key for enity table; only fk componded for relationship table
The entity table should have one and only one column of PK.
The pk can be configured as an auto key, which can be referenced by child table and been handled in a batched DB committing.
It's recommended the relationship tables have no primary key of itself, the multiple FK referencing parents should be used as commpond primary keys.
Take author - publisher relationship for example, if we need a table representing their contracts, a relationship table can be designed as:
	table relations:
		column author-id,    -- fk to authors.author-id
		column publisher-id, -- fk to publishers.publisher-id
		column contract-id   -- fk to contracts.contract-id
All of these 3 columns are FKs.

If database design followed this rule, the relationship table can be auto handled by sematnic.DA, with 3 FK semantics (type = 'fk') to support auto insertion, and with 'pc-del-all' to delete all relation records when deleting parent.

If you added another column as primary key, the semantics.DA's auto key can't support multiple insertions when inserting relationships.

For more about semantics type, see semantics.DA javadoc on io.odysz.semantic Enum DASemantics.smtype.

For semantics.xml, see the sample project's semantics.xml .