The @Column annotation in JPA maps an entity field or property to a specific database column and lets you control that column's name, nullability, length, uniqueness, numeric precision and whether it is included in inserts and updates. It is optional: without it JPA maps the field to a column using the default naming strategy. You add it when the default is not what your schema needs.
In current versions the annotation lives in the jakarta.persistence package (Jakarta Persistence 3.x, used by Hibernate 6 and Spring Boot 3 and later). Older code uses javax.persistence, which is the same API under its former name.
An entity is a class annotated with @Entity. Each persistent field becomes a column. @Column is placed on the field, or on the getter when you use property access.
Here name is stored in a column called employee_name, marked NOT NULL and limited to VARCHAR(100) when the schema is generated.
| Attribute | Default | Purpose |
|---|---|---|
name | field name (after the naming strategy) | Column name |
nullable | true | Adds NOT NULL to generated DDL when false |
length | 255 | Size of string columns |
unique | false | Adds a unique constraint in generated DDL |
precision, scale | 0 | Digits for BigDecimal and similar types |
insertable | true | Include the column in INSERT statements |
updatable | true | Include the column in UPDATE statements |
columnDefinition | provider default | Raw SQL fragment for the column type |
table | primary table | Column lives in a secondary table |
Column names are case-insensitive in most databases, so keep them lowercase with underscores.
An important point that is often missed: nullable, length, unique, precision and scale only affect schema generation (for example hibernate.hbm2ddl.auto or jakarta.persistence.schema-generation). They do not replace validation. Hibernate does not check length at runtime, and the database raises the error instead. Use Bean Validation (@NotNull, @Size) for checks before the SQL runs. For production schemas, manage DDL with a migration tool such as Flyway or Liquibase and keep the annotations consistent with it.
sku is a required, unique string of at most 40 characters.price allows ten digits in total with two after the decimal point, a normal choice for money. Use BigDecimal, never double, for currency.createdBy is written on insert and never changed by later updates.searchVector is read but never written, which suits a column the database computes itself, such as a generated column or one filled by a trigger.columnDefinition passes an exact SQL fragment into the generated DDL.
This ties the mapping to one database dialect and is ignored when you do not generate the schema from entities. Prefer portable attributes (length, precision) and put database-specific details in migration scripts. For large text, @Lob or a provider type such as Hibernate's @JdbcTypeCode is often cleaner.
In Spring Boot with Hibernate, the default physical naming strategy converts camel case to snake case, so firstName maps to first_name even without @Column. An explicit @Column(name = "...") is passed through the naming strategy as well, so you normally write the final snake case name. Avoid column names that are SQL reserved words such as order or user. If you must use one, rename the column rather than relying on quoting.
No. Every non-transient field of an entity is mapped by default. Add @Column only when you need a different name or specific constraints.
Not at runtime in the way most people expect. It affects generated DDL and lets the provider optimise some checks. Use Bean Validation such as @NotNull to reject bad input early, and keep the database constraint as the final safeguard.
@Column maps a basic value such as a string or number. @JoinColumn maps the foreign key column of an association such as @ManyToOne.
Use jakarta.persistence for Spring Boot 3 and later, Hibernate 6 and Jakarta EE 9 and newer. javax.persistence belongs to older stacks.
@Column gives you precise control over how a field maps to a database column: name, nullability, length, precision, uniqueness and insert or update behaviour. Treat the constraint attributes as schema generation hints, add Bean Validation for runtime checks, prefer migrations for production DDL, and import from jakarta.persistence on modern stacks.