Skip Headers

Oracle TopLink Developer's Guide 10g Release 3 (10.1.3) B13593-01 |
| Home | Solution Area | Contents | Index

Previous | Next |

# Configuring a Default Null Value at the Mapping Level

A default null value is the Java `Object` type and value that TopLink uses instead of `null` when TopLink reads a null value from a data source.

When you configure a default null value at the mapping level, TopLink uses it to translate in two directions:

- When TopLink reads `null` from the data source, it converts this `null` to the specified type and value.

- When TopLink writes or queries to the data source, it converts the specified type and value back to `null`.

Table 35-6 summarizes which mappings support this option.

Table 35-6 Mapping Support for Default Null Values

Mapping | Using TopLink Workbench | Using Java
--- | --- | ---
Relational Mappings |  |
Direct-to-Field Mapping |  |
Direct to XMLType Mapping |  |
EIS Mappings |  |
EIS Direct Mapping |  |
XML Mappings |  |
XML Direct Mapping |  |
XML Composite Direct Collection Mapping |  |

Note: A default null value must be an `Object`. To specify a primitive value (such as `int`), you must use the corresponding `Object` wrapper (such as `Integer`).

You can also use TopLink to set a default null value for all mappings used in a session (see "Configuring a Default Null Value at the Login Level").

## Using TopLink Workbench

To configure a default null value for a mapping, use this procedure.

1. Select the mapped attribute in the Navigator. Its properties appear in the Editor.

2. Click the General tab. The General tab appears.

   Figure 35-6 General Tab, Default Null Value Options

   Description of "Figure 35-6 General Tab, Default Null Value Options"

Use the following information to complete the Default Null Value fields on the tab:

Field | Description
--- | ---
Default Null Value | Specify if this mapping contains a default value in the event that the data source is `null`. If selected, you must enter both the Type and Value of the default.
Type | Select the Java type of the default value.
Value | Enter the default value.

## Using Java

To configure a mapping null value using Java API, use the `AbstractDirectMapping` method `setNullValue`.

For example:

    // Defaults a null salary to 0
    salaryMapping.setNullValue(new Integer(0));