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. 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-5 Direct-to-Field Mapping Example

Figure 5-10 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-10 Direct-to-Field Mapping

This figure shows a direct-to-field mapping between from a Java class to a relational database.


Related Topics

About TopLink Mapping Types
Working with Direct Mappings

 

Creating Direct-to-Field Mappings for Java Objects
Creating Direct-to-Field Mappings for CMP EJBs

 

Copyright © 1997, 2004, Oracle. All rights reserved.