primaryKey
boolean primaryKey()
- Returns:
- true if this column is part of a primary key
T - the underlying typeAttributeDefinition<T>, ValueAttributeDefinition<T>
ColumnDefinition extends ValueAttributeDefinition with column-specific configuration
such as primary key properties, SQL expressions, insertable/updatable flags, and
database value conversion logic.
Column definitions are created through the column builder API:
interface Invoice {
EntityType TYPE = DOMAIN.entityType("chinook.invoice");
Column<Long> ID = TYPE.longColumn("id");
Column<LocalDate> DATE = TYPE.localDateColumn("invoicedate");
Column<String> BILLINGCITY = TYPE.stringColumn("billingcity");
Column<BigDecimal> TOTAL = TYPE.bigDecimalColumn("total");
Column<LocalDateTime> INSERT_TIME = TYPE.localDateTimeColumn("insert_time");
}
EntityDefinition invoice() {
return Invoice.TYPE.as()
.attributes(
// Primary key with auto-generation
Invoice.ID.as()
.primaryKey()
.generator(Generator.identity()),
// Required column
Invoice.DATE.as()
.column()
.caption("Date")
.nullable(false),
// String column with length constraint
Invoice.BILLINGCITY.as()
.column()
.caption("Billing city")
.maximumLength(40),
// Decimal column with precision and range validation,
// the database providing a default value
Invoice.TOTAL.as()
.column()
.caption("Total")
.nullable(false)
.minimum(0)
.fractionDigits(2)
.withDefault(true),
// Audit column (database-managed)
Invoice.INSERT_TIME.as()
.column()
.caption("Inserted")
.insertable(false) // Not included in INSERT
.updatable(false) // Not included in UPDATE
.withDefault(true)) // Database provides a default value
.build();
}
static interface ColumnDefinition.Builder<T,B extends ColumnDefinition.Builder<T,B>> ColumnDefinitionAttributeDefinition.DefaultValue<T>DECIMAL_SEPARATOR, DESCRIPTION_RESOURCE_SUFFIX, FRACTION_DIGITS, GROUPING_SEPARATOR, LEXICAL_STRING_COMPARATOR, MNEMONIC_RESOURCE_SUFFIX, NUMBER_GROUPING, ROUNDING_MODETRIM_STRINGSbooleanAttribute this definition is based on, should be unique within an Entity.<C> Column.Converter<C,T> booleanResultSetResultSet by namebooleangroupBy()booleanintkeyIndex()name()booleanbooleanreadOnly()booleanbooleanselected()voidset(PreparedStatement statement,
int index,
@Nullable T value,
Database database) PreparedStatementintsqlType()booleanbooleancaption, comparator, dateTimeFormatter, dateTimePattern, derived, description, entityType, format, format, fractionDigits, hidden, mnemonic, roundingModedefaultValue, hasDefaultValue, items, maximum, maximumLength, minimum, nullable, trim, validate, validItemAttributeDefinitionAttribute this definition is based on, should be unique within an Entity.
By default, the Attribute.name() serves as column name for database columns.attribute in interface AttributeDefinition<T>Types).Column.Generator used to populate the value of this columnIllegalStateException - in case a generator is not availableC - the column value typeColumn.Converter for this column.ResultSetresultSet - the ResultSetindex - this columns index in the resultdatabase - the Database providing the default value gettersResultSetSQLException - in case of an exceptionResultSet by nameresultSet - the ResultSetdatabase - the Database providing the default value gettersResultSetSQLException - in case of an exceptionPreparedStatementstatement - the statementindex - the parameter indexvalue - the value to set, may be nulldatabase - the Database providing the default parameter settersSQLException - in case of an exception