<DefaultValue> Element

Initialises a persistent field with a default value from the database.

<PersistentField [fieldName="fieldName"]>

              serverInitialized="is-server-initialized" />



<PersistentField [fieldName="fieldName"]



db-default-value: the database expression used for initialising the default value of the field when a new row is created. This can be any expression allowed by the underlying database platform.

is-server-initialized: If set to true or omitted, the field is initialised by the database. If set to false, the specified default value will be included in the database creation script, but it will not be used for initialising the field.

enabled: If set to true, the field is initialised with a server-side specified default value.


·    Using the DefaultValue element with the serverInitialized=”false” option does not change the insert behavior of Genome. It can be used for documenting a default value constraint of the database. The following remarks are valid for the case when serverInitialized=”false” was not specified.

·    When the object is created and committed to the database, Genome does not insert values into fields that have been mapped with DefaultValue and were not updated on the client side. Fields that are updated on the client side are not initialised with the default value of the database but with the client-side set value.

·    How a property mapped with DefaultValue, that has not been set on the client side and where the object has not been committed yet, is accessed depends on the transaction model used:

o    When using ShortRunningTransactionContext, property access causes a Context.Flush() and the property returns the database-initialised value.

o    When using LocalContext, property access causes a GenomeException (#GEN0151) with an error message that the server-side initialised property can only be accessed after committing the object to the database.

·    When using the attribute notation (DefaultValue="true"), the generated DDL script uses a placeholder for specifying the default value, that has to be manually replaced before executing the script. This can be used when mapping to an existing database that does not have to be recreated with Genome.

·    With SQL Server 2005, this mapping feature can also be used to initialise primary key fields (see also <SequentialGuid> mapping element).

·    When applied to a primary key field, the mapped property has to be read only (i.e. can only have a getter).


Editions:Professional, Evaluation, Express

Database Platforms:Microsoft SQL Server 2000, Microsoft SQL Server 2005, Oracle 9i Release 2, Oracle 10g Release 2, IBM DB2