Annotation Type Column


@Retention(CLASS) @Target(FIELD) public @interface Column
Renames or constrains an @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).
  • Optional Element Summary

    Optional Elements
    Modifier and Type
    Optional Element
    Description
    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.
    boolean
    When false the column is left out of every INSERT the ORM writes, so the row starts with the column's database default.
    Column name.
    boolean
    When false the column gets a NOT NULL constraint at table-create time.
    Optional explicit SQL type.
    boolean
    Creates a unique index when the managed schema is created.
    boolean
    When false the column is left out of every UPDATE the ORM writes for a changed entity, so a save never overwrites it.
  • Element Details

    • name

      String name
      Column name. When blank the app uses the field name and the backend the field name in snake case (fareCents becomes fare_cents), the default Spring Boot applies.
      Default:
      ""
    • nullable

      boolean nullable
      When false the column gets a NOT NULL constraint at table-create time.
      Default:
      true
    • unique

      boolean unique
      Creates a unique index when the managed schema is created.
      Default:
      false
    • type

      String type

      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).

      Default:
      ""
    • insertable

      boolean insertable
      When false the column is left out of every INSERT the ORM writes, so the row starts with the column's database default. The field's value at insert time is ignored, not written.
      Default:
      true
    • updatable

      boolean updatable
      When false the column is left out of every UPDATE 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.
      Default:
      true
    • collation

      String collation

      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.

      Default:
      ""