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 Product {
EntityType TYPE = DOMAIN.entityType("store.product");
Column<Integer> ID = TYPE.integerColumn("id");
Column<String> NAME = TYPE.stringColumn("name");
Column<BigDecimal> PRICE = TYPE.bigDecimalColumn("price");
Column<LocalDateTime> CREATED_DATE = TYPE.localDateTimeColumn("created_date");
}
Product.TYPE.define(
// Primary key with auto-generation
Product.ID.define()
.primaryKey()
.generator(Generator.identity()),
// Required string column with length constraint
Product.NAME.define()
.column()
.nullable(false)
.maximumLength(100),
// Decimal column with precision and range validation
Product.PRICE.define()
.column()
.nullable(false)
.minimum(BigDecimal.ZERO)
.maximum(new BigDecimal("99999.99"))
.fractionDigits(2),
// Audit column (database-managed)
Product.CREATED_DATE.define()
.column()
.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.ValueSupplier<T>DESCRIPTION_RESOURCE_SUFFIX, MNEMONIC_RESOURCE_SUFFIXDECIMAL_SEPARATOR, DEFAULT_FRACTION_DIGITS, FRACTION_DIGITS, GROUPING_SEPARATOR, NUMBER_GROUPING, ROUNDING_MODE, TRIM_STRINGS, USE_LEXICAL_STRING_COMPARATORbooleanAttribute this definition is based on, should be unique within an Entity.<C> Column.Converter<C,T> booleanResultSet by nameResultSetbooleangroupBy()booleanintkeyIndex()name()booleanbooleanreadOnly()booleanbooleanselected()voidset(PreparedStatement statement,
int index,
@Nullable T value) PreparedStatementinttype()booleanbooleancaption, comparator, defaultValue, description, entityType, format, hasDefaultValue, hidden, mnemonic, nullable, validate, validatedateTimeFormatter, dateTimePattern, derived, format, fractionDigits, items, maximum, maximumLength, minimum, roundingMode, trim, 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 colum value typeColumn.Converter for this column.ResultSetresultSet - the ResultSetindex - this columns index in the resultResultSetSQLException - in case of an exceptionResultSet by nameresultSet - the ResultSetResultSetSQLException - in case of an exceptionPreparedStatementstatement - the statementindex - the parameter indexvalue - the value to set, may be nullSQLException - in case of an exception