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.as(
// Primary key with auto-generation
Product.ID.as()
.primaryKey()
.generator(Generator.identity()),
// Required string column with length constraint
Product.NAME.as()
.column()
.nullable(false)
.maximumLength(100),
// Decimal column with precision and range validation
Product.PRICE.as()
.column()
.nullable(false)
.minimum(BigDecimal.ZERO)
.maximum(new BigDecimal("99999.99"))
.fractionDigits(2),
// Audit column (database-managed)
Product.CREATED_DATE.as()
.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.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) PreparedStatementinttype()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 colum 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