@Column Annotation in JPA Configurations
Fast recall
Quick revision
Core answer
name, nullable (NOT NULL), length (VARCHAR size), unique, and columnDefinition (custom SQL type). Without it, JPA defaults to the field name, nullable, VARCHAR(255). Key trap: `nullable = false` only affects DDL, not runtime — for runtime checks add Bean Validation (@NotNull/@NotBlank).Whether you can shape the schema with @Column and know it controls DDL, not runtime validation
Believing nullable=false validates data at runtime, or leaving every String at the default VARCHAR(255)
Distinguish @Column (DDL) from Bean Validation (runtime), and use columnDefinition sparingly to keep portability
Interview-ready guide
Interview answer
The Column annotation lets me customize how a field maps to a column.
Without it, JPA uses the field name as the column name and applies defaults like nullable true and VARCHAR 255. In real apps I need more control. The name attribute helps when the database uses snake case like user underscore name but my field is camelCase.
The nullable attribute controls whether the column allows null — set it to false and Hibernate generates a not-null constraint in the create table statement. But here's the key trap: nullable false only affects the schema, the DDL. It does not validate my data at runtime.
If I try to save an entity with a null field, JPA won't stop me until the database rejects it. For runtime validation I need Bean Validation annotations like NotNull or NotBlank, plus Valid on the controller parameter. The length attribute sets the VARCHAR size, since the default 255 is wasteful — I'd use fifty for a username, a hundred for an email, two thousand for a description.
The unique attribute adds a unique constraint, good for emails or usernames. And columnDefinition lets me set an exact SQL type like JSONB in PostgreSQL or decimal ten comma two for money, but I use it sparingly because it ties me to one database.
The thing to remember is that Column shapes the schema, and if I want to reject bad input before it hits the database, I combine it with Bean Validation.
@Column Annotation in JPA Configurations
Direct Answer
@Column customizes the field-to-column mapping: name, nullable (NOT NULL), length (VARCHAR size), unique, and columnDefinition (custom SQL type). Without it, JPA defaults to the field name, nullable, VARCHAR(255). Key trap: nullable = false only affects DDL, not runtime — for runtime checks add Bean Validation (@NotNull/@NotBlank).
Common Mistakes & Pitfalls
nullable=false≠ validation — it's DDL only; add@NotNull/@NotBlankplus@Validfor runtime checks.- Leaving all Strings at VARCHAR(255) — set realistic
length(50 username, 100 email, 2000 description). - Overusing
columnDefinition— hardcoded SQL types break portability; reserve for DB-specific features. - Composite uniqueness via
@Column(unique=true)— that makes each column individually unique; use@Table(uniqueConstraints=...).
Check your understanding
Answer these without looking back at the article.
- What is the difference between @Column(nullable=false) and @NotNull?
- What is the default length for @Column?
- How do you map a BigDecimal to a database decimal column?
Looking for a structured roadmap?
Every module on this page is also part of the full Java backend interview track.