How does a mapper turn class and property names into table and column names, and when must you override that?
answer
- one function, every undeclared name
- case, separators, composed names
- override globally or per element
- quoting pins the exact spelling
- truncation can collide two identifiers
basics
~20 sA naming strategy derives every identifier nobody declared, turning class names into table names and property names into column names, usually with case conversion. Replace the strategy for a schema-wide rule; declare one name for a legacy exception.
solid answer
~50 sUndeclared identifiers are produced by a **naming strategy** — a single function from a model name to a database name. Typical transformations are case conversion, inserting a separator between words, and sometimes pluralising a table name; link tables and key columns get composed names built from the same rule. Because it is one function over the whole model, it decides most of the schema at once. Overrides come at three scopes: replace the strategy globally when the whole schema follows a different house rule; declare an explicit name on one class or one property for a legacy table or a column whose name is a reserved word; and quote an identifier when it must be matched exactly, accepting that quoting usually makes the name case-sensitive. Watch identifier length limits: a composed name can exceed the database's maximum and be truncated into a collision.
go deeper
Know that undeclared table and column names are derived from class and property names by a rule, and that a single explicit declaration can override that rule for one element.
Explain the transformations a strategy applies, the difference between replacing the strategy and declaring one name, and why a rename in the model can become a schema change.
Talk about mapping onto a schema you did not design: prefixes and abbreviations encoded in a strategy, explicit names for the exceptions, and validation that fails at startup when the two drift apart.
Treat naming as a schema-wide contract: who owns identifier conventions, whether the model or the schema is the source of truth, and how renames are allowed to propagate across teams.
When mapping metadata does not state a table or column name, something still has to produce one. That something is a **naming strategy**: a deterministic function from the names in the model to the identifiers in the database. It is the least visible part of a mapping and one of the most consequential, because it decides every identifier that nobody wrote down. ## What a strategy typically does - **Case conversion.** Model code and database schemas rarely share a casing convention, so a strategy usually rewrites mixed-case member names into the schema's house style. - **Word separation.** A multi-word name is split at its word boundaries and rejoined with the separator the schema uses. - **Table name shape.** Some layers use the class name as-is, others pluralise it; both are defensible and the choice is the strategy's, not the mapper's nature. - **Composed names.** Identifiers the model never named — the column holding a link, or the table standing between two collections — are composed from the names of the participants by the same rule. - **Length limits.** Databases cap identifier length. A composed name can exceed the cap and be truncated, and two different composed names can truncate to the same identifier. ## Three scopes of override 1. **Replace the strategy.** The whole schema follows a different rule from the layer's default. Changing one function fixes every identifier at once, and the model stays free of per-element declarations. 2. **Declare one element explicitly.** A single legacy table, or a column whose natural name collides with a reserved word, gets a stated name while everything around it stays derived. 3. **Quote the identifier.** Some databases fold unquoted identifiers to a single case; quoting preserves the exact spelling but usually makes the name case-sensitive from then on, so every other reference must match it exactly. The order matters when you are diagnosing a wrong name: an explicit declaration beats the strategy, and the strategy only fills gaps. ## Choosing between a global change and a local one | Situation | Right scope | Why | |---|---|---| | Whole schema uses a different casing or separator | Replace the strategy | One change, no per-element noise, new classes conform automatically | | One legacy table nobody may rename | Explicit name on that class | Keeps the convention intact for everything else | | A handful of columns whose names are reserved words | Explicit or quoted names on those columns | The problem is per-identifier, not systemic | | Names that must match a schema exactly, including case | Quoting, applied consistently | Prevents case folding from silently changing the identifier | A frequent mistake is reaching for the global lever to fix one name. Changing the strategy to accommodate a single legacy table rewrites every other identifier in the model, which is a schema-wide change made for one row of the problem. ## Legacy schemas Mapping onto a schema you did not design is where naming stops being cosmetic. The schema will contain abbreviations, historical prefixes, columns whose names encode a system that no longer exists, and identifiers that were once truncated. Two workable approaches exist, and they can be mixed: write explicit names everywhere and treat the strategy as irrelevant, or write a strategy that encodes the legacy rule — the prefix, the abbreviation table — and declare only the genuine exceptions. The second is worth it once the exceptions are a minority of the whole. ## Why the default is a decision Because the strategy runs on everything, a property rename is also a column rename. In a system where the schema is generated from the model, that is a migration nobody wrote; in a system where the schema is authored by hand and the mapping is validated against it, that is a startup failure. Both outcomes are better than the third: a layer that quietly maps to a new column that does not exist, or maps two members onto one truncated identifier. This is why a validation step comparing the resolved mapping against the live schema is worth its cost — it turns naming drift into a loud, early error. ## What to say in an interview Name the strategy as a single function, give two of its transformations, then explain the three override scopes and the case in which each is correct. Mentioning identifier length truncation and case folding on quoted identifiers signals that you have mapped onto a schema you did not control.
- Why can quoting an identifier create more problems than it solves?Unquoted identifiers are usually folded to one case, so they match loosely. A quoted identifier is taken literally, which means every other reference — other mappings, hand-written statements, tooling — must reproduce the exact spelling. Applied to a few names in a schema that otherwise relies on folding, it produces mismatches that only appear at query time.
- What can go wrong when the mapper composes a name for something the model never named?Composed names are built from the participants, so they get long. When the composed name exceeds the database's identifier limit it is truncated, and two different composed names can truncate to the same identifier, producing a collision that looks like a mapping bug rather than a naming one. Declaring those names explicitly avoids it.
- Should renaming a property be allowed to rename a column?Only if the schema is generated from the model and the rename is carried by a migration. Where the schema is authored separately, the safe arrangement is an explicit name on load-bearing columns, or a validation at startup that fails when the resolved mapping no longer matches the schema.
saying these in an interview costs you the question
- Thinks derived names are arbitrary rather than a stated rule
- Changes the global strategy to fix one legacy table name
- Believes quoting an identifier has no further consequences
- Ignores identifier length limits and the collisions truncation causes
- Assumes a property rename is safe because nothing else references it