Annotation Interface Column
Annotation for customizing field-to-column mapping.
By default, field names are converted to snake_case. Use this annotation to specify a custom column name, mark a field as transient, control nullability, default values, and indexing.
Example:
@Entity
public class UserData {
private Long id;
@Column(name = "discord_user_id", nullable = false)
private Long userId;
@Column(defaultValue = "true")
private Boolean enabled;
@Column(unique = true)
private String email;
@Column(index = true)
private String username;
@Column(ignore = true)
private transient String cachedValue; // Not persisted
}
-
Optional Element Summary
Optional ElementsModifier and TypeOptional ElementDescriptionDefault value for the column (SQL expression).booleanWhether this field should be ignored during persistence.booleanWhether to create a regular index on this column.Custom column name.booleanWhether the column allows NULL values.booleanWhether to create a unique index on this column.
-
Element Details
-
name
String nameCustom column name.If empty, the field name is converted to snake_case.
- Returns:
- the column name
- Default:
""
-
ignore
boolean ignoreWhether this field should be ignored during persistence.- Returns:
- true to ignore this field
- Default:
false
-
nullable
boolean nullableWhether the column allows NULL values.If not specified, nullability is inferred from the field type: primitive types are non-nullable, wrapper types are nullable.
- Returns:
- true if nullable, false if not nullable, default is inferred
- Default:
true
-
defaultValue
String defaultValueDefault value for the column (SQL expression).Example: "true", "0", "'default_text'", "CURRENT_TIMESTAMP"
- Returns:
- the default value expression, or empty string for none
- Default:
""
-
unique
boolean uniqueWhether to create a unique index on this column.- Returns:
- true to create a unique index
- Default:
false
-
index
boolean indexWhether to create a regular index on this column.- Returns:
- true to create an index
- Default:
false
-