Oracle® Application Server TopLink Mapping Workbench User's Guide
10g Release 2 (10.1.2) Part No. B15900-01 |
|
Previous |
Next |
Direct-to-field mappings map a Java attribute directly to a value database column. When the application writes a Java instance to the database, it stores the value of the attribute in a field of the table column. OracleAS TopLink supports the following types:
java.lang
: Boolean
, Float
, Integer
, String
, Double
, Long
, Short
, Byte
, Byte[ ]
, Character
, Character[ ]
; all of the primitives associated with these classes
java.math
: BigInteger
, BigDecimal
java.sql
: Date
, Time
, Timestamp
java.util
: Date
, Calendar
While reading, direct-to-field mappings perform some simple one-data conversions, as described in Table 5-1. You must use other direct mappings for two-way or more complete conversions.
Table 5-1 Type Conversions Provided by Direct-to-Field Mappings
Direct-to-field mappings also allow you to specify a null value. This may be required if primitive types are used in the object, and the database field allows null values.
Example 5-1 Direct-to-Field Mapping Example
Figure 5-1 illustrates a direct-to-field mapping between the Java attribute city and the relational database column CITY. Similarly, direct-to-field mappings could be defined from country to COUNTRY, id to ADDRESS_ID, established to EST_DATE, and province to PROVINCE.
Use this procedure to create a basic direct-to-field mapping to map a Java attribute directly to a value in a database.
To create a direct-to-field mapping:
Select the attribute to be mapped from the Navigator pane.
Description of the illustration dtfmpbtn.gif
Click the Direct to Field Mapping button on the mapping toolbar.
From the Database Field drop-down list on the General tab on the Editor pane, choose the appropriate database field.
Select the Use Default Value When Database Field is Null option to specify a default Type and Value to use if the database field is null.
You can also specify:
Read-only attributes – See "Specifying Read-Only Settings" on page 4-72
Access methods – See "Specifying Direct Access and Method Access" on page 4-71
Null values – See "Defaulting Null Values" on page 4-73