Oracle TopLink Developer's Guide
10g Release 3 (10.1.3) B13593-01 |
|
![]() Previous |
![]() Next |
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
|
---|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
XML Composite Direct Collection Mapping |
|
|
Note: A default null value must be anObject . 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").
To configure a default null value for a mapping, use this procedure.
Select the mapped attribute in the Navigator. Its properties appear in the Editor.
Click the General tab. The General tab appears.
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. |
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));