Client and backend. This class is shared: the same code is compiled into your app and into your server, so everything on this page works in both.
@Retention(CLASS) @Target({FIELD})
public @interface Column
@Entity field’s column. Optional – when absent,
the column name defaults to the field name (in snake case on the backend)
and the type is inferred from the Java field type (String -> TEXT, int/long -> INTEGER,
float/double -> REAL, boolean -> INTEGER, byte[] -> BLOB,
java.util.Date -> INTEGER).Methods
public abstract String name() default "" | Column name. |
public abstract boolean nullable() default true | When false the column gets a NOT NULL constraint at table-create time. |
public abstract boolean unique() default false | Creates a unique index when the managed schema is created. |
public abstract String type() default "" | Optional explicit SQL type. |
public abstract boolean insertable() default true | When false the column is left out of every INSERT the ORM writes, so the row starts with the column’s database default. |
public abstract boolean updatable() default true | When false the column is left out of every UPDATE the ORM writes for a changed entity, so a save never overwrites it. |
public abstract String collation() default "" | The collation of the column, appended to its DDL as COLLATE <name> (quoted on PostgreSQL), and the one the schema report then holds an existing column to instead of requiring a case-sensitive key collation. |
Method details
name
public abstract String name() default ""fareCents becomes fare_cents), the
default Spring Boot applies.nullable
public abstract boolean nullable() default trueNOT NULL constraint at table-create time.unique
public abstract boolean unique() default falsetype
public abstract String type() default ""Optional explicit SQL type. Use the SQLite type names (TEXT,
INTEGER, REAL, BLOB, NUMERIC). When blank the processor infers
the type from the field’s Java type.
On the backend the value is written through to the CREATE TABLE
unchanged, so it is engine specific by construction: a type only
PostgreSQL understands makes the entity PostgreSQL-only. Leaving it blank
keeps the entity portable, because the dialect then names the type each
engine spells differently (TEXT/VARCHAR, REAL/DOUBLE PRECISION,
BLOB/BYTEA).
insertable
public abstract boolean insertable() default trueINSERT the ORM writes, so the
row starts with the column’s database default. The field’s value at
insert time is ignored, not written.updatable
public abstract boolean updatable() default trueUPDATE the ORM writes for a
changed entity, so a save never overwrites it. The column can still be
written by a query of the application’s own – a @Modifying @Query that
claims a row with a compare-and-swap, for example – which is what makes
insertable = false, updatable = false a column only that statement owns.
A change made to the field alone is ignored: it neither writes the column
nor marks the entity dirty.collation
public abstract String collation() default ""The collation of the column, appended to its DDL as COLLATE <name>
(quoted on PostgreSQL), and the one the schema report then holds an
existing column to instead of requiring a case-sensitive key collation.
Letters, digits and underscores only, as utf8mb4_0900_ai_ci on MySQL,
NOCASE on SQLite or a collation created on PostgreSQL.
A case-insensitive collation on a key makes the database treat "A" and
"a" as one key. The session’s identity cache still compares ids with
String.equals, so look an entity up by the spelling it is stored with:
another one finds the row but loads a second instance of it. Hibernate
has the same caveat.