Mapping
Declare an entity that will survive production, not just the first test.
Entity Mapping
Declaring a JPA entity takes three annotations. Declaring an entity that won't cause problems two years from now takes about a dozen decisions, four of which are irreversible once there is data in the database.
The most expensive of these decisions concerns enumerations. JPA's default setting stores an enumeration as a positional integer: EN_ATTENTE becomes 0, PAYEE becomes 1. The day a developer inserts a value in the middle of the list — something any programming language allows without consequence — every row already written changes meaning. Paid orders become canceled orders. There is no error message and no exception: just data that no longer means what it used to.
The second costly decision is the primary key, because it determines whether writes can be grouped into batches. The third is the choice between a simple field and a shared value type. The fourth is the inheritance strategy, which fixes the shape of the tables and therefore the cost of every future read.
This lesson walks through these choices, showing the PostgreSQL DDL produced each time. It is the only way to verify that an annotation does what you think it does.
Comments
Comments are powered by GitHub Discussions
Sign in with GitHub to join the discussion