In the previous section, we saw that the
element can take either a
column elements. This option is repeated
on many elements throughout mapping metadata. The motivation for this
dualistic approach is to make the common case easy, but retain
the flexibility to handle more complex scenarios. When a mapping has
a single column with default properties, you can use the
column attribute to just name the column. When, on the
other hand, a mapping has multiple columns or columns with non-default
properties, you can fall back to nested
elements. We saw this in
Example 15.3, “Datastore Identity Mapping” above: most classes
column attribute to simply name the
primary key column, but
Magazine used a nested element in order to
specify additional column information. Column elements have the
name: The column name. Later in this
chapter, we will come across situations where a column is not
in the expected table. In these cases, you can specify the
column name as
<table-name>.<column-name>, or even
The column name is required for runtime use. The reason the
name attribute isn't marked
#REQUIRED in the DTD is that some vendors
may allow you to partially-specify column information during
the mapping process, and have the rest filled in by a
jdbc-type: Determines what JDBC APIs the
implementation uses to load and store data to the column.
This attribute is only required when the column uses a
non-default type for the associated data - for example,
String is mapped to a
CLOB column rather than a
Standard values for this attribute include all of the constant
names from the
java.sql.Types class, in
either uppercase or lowercase: BIGINT, bigint, BLOB, blob,
DECIMAL, decimal, VARCHAR, varchar, etc.
sql-type: The database-specific column type
name. This attribute is only used by vendors that support
creating tables from your mapping metadata. During table
creation, the vendor will use the text of the
sql-type attribute as the declared column
type. If no
sql-type is given, the vendor
will choose an appropriate default based on the
column's JDBC type, length, and scale.
length: The column length. This attribute
is typically only used during table creation, though some
vendors might use it to validate data before flushing.
columns typically default to a length of 255; other
column types use the database default.
allows-null: Whether the column can store
null values. Vendors may use this attribute both for table
creation and at runtime; however, it is never required.
false for primary key columns
and columns holding primitive field values, and
true for all other columns.
default-value: A database-assigned default
value for the column if no value is given in the
INSERT SQL. Vendors will pass this default on to the
database during table creation. When a new object is being
persisted with Java default field values, vendors may use this
attribute to decide whether to include the columns for those
fields in the generated
Kodo uses a combination of a column's default value and JDO
Kodo also defines extensions to mark that the current mapping should not attempt to insert or update a column's value. See Section 7.9.3, “Column Extensions” in the Reference Guide.