Skip Headers
Oracle® Application Server TopLink Mapping Workbench User's Guide
10g Release 2 (10.1.2)
Part No. B15900-01
  Go To Documentation Library
Home
Go To Product List
Solution Area
Go To Table Of Contents
Contents
Go To Index
Index

Previous
Previous
Next
Next
 

Working with Direct-to-Field Mappings

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:

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

Java type Database type
Integer, Float, Double, Byte, Short, BigDecimal, BigInteger, int, float, double, byte, short NUMBER, NUMERIC, DECIMAL, FLOAT, DOUBLE, INT, SMALLINT, BIT, BOOLEAN
Boolean, boolean BOOLEAN, BIT, SMALLINT, NUMBER, NUMERIC, DECIMAL, FLOAT, DOUBLE, INT
String VARCHAR, CHAR, VARCHAR2, CLOB, TEXT, LONG, LONG VARCHAR, MEMO
nSting NVARCHAR2 (applies to Oracle9)
nClob NCLOB (applies to Oracle9)
Character, char CHAR
nChararcter NCHAR (applies to Oracle9)
byte[ ] BLOB, LONG RAW, IMAGE, RAW, VARBINARY, BINARY, LONG VARBINARY
Time TIME
sql.Date DATE (only applies to DB2)
Timestamp, util.Date, Calendar TIMESTAMP (only applies to DB2)
sql.Date, Time, Timestamp, util.Date, Calendar DATE, DATETIME (applies to Oracle, Sybase, SQL Server)

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.

Figure 5-1 Direct-to-Field Mapping

Description of dtfmpfig.gif follows
Description of the illustration dtfmpfig.gif

Creating Direct-to-Field Mappings

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:

  1. Select the attribute to be mapped from the Navigator pane.

  2. Direct to Field Mapping button.
    Description of the illustration dtfmpbtn.gif

    Click the Direct to Field Mapping button on the mapping toolbar.

  3. From the Database Field drop-down list on the General tab on the Editor pane, choose the appropriate database field.

  4. 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.

Figure 5-2 Direct-to-field Mapping Properties

Description of dtfmptab.gif follows
Description of the illustration dtfmptab.gif

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