Oracle TopLink Developer's Guide
10g Release 3 (10.1.3) B13593-01 |
|
![]() Previous |
![]() Next |
This section introduces direct mapping concepts unique to TopLink, including:
All TopLink relational mappings are unidirectional, from the class being described (the source class) to the class with which it is associated (the target class). The target class does not have a reference to the source class in a unidirectional relationship. To implement a bidirectional relationship (classes that reference each other), use two unidirectional mappings with the sources and targets reversed.
You can store object attributes directly in a database table:
If the attribute type is comparable to a database type, the information can be stored directly simply by using a direct-to-field mapping (see "Direct-to-Field Mapping").
If the attribute type is comparable to a database type but requires conversion, the information can be stored directly by using a direct-to-field mapping (see "Direct-to-Field Mapping") and an appropriate Converter
instance.
In the previous release, TopLink provided subclasses of DirectToFieldMapping
for object type direct mappings, serialized object direct mappings, and type conversion direct mappings. In this release, these subclasses are deprecated. In their place, Oracle recommends that you use the DirectToFieldMapping
method setConverter
and the corresponding Converter
instance. Table 36-2 summarizes these changes.
Table 36-2 Using a Converter for Direct to Field Mappings
Deprecated DirectToFieldMapping subclass... | Replaced by Converter instance... |
---|---|
|
|
|
|
|
|
If the application's objects contain attributes that cannot be represented as direct-to-field with an existing converter, use a direct-to-field mapping with a custom converter.
If there is no database primitive type that is logically comparable to the attribute's type, or, if an attribute requires data from multiple fields, it must be transformed on its way to and from the database.
In this case, use a transformation mapping (see "Transformation Mapping").
Use direct mappings to map the (non-CMR) CMF attributes of a bean.
In EJB 2.0 CMP projects, the bean class does not define real variables in the class – only abstract getter and setter methods. To map the bean's attributes, you must import ejb-jar.xml
file into TopLink Workbench (see "Configuring Persistence Type").
In EJB 1.1 CMP and BMP projects, the bean's CMF attributes are mapped as normal.
You can map entity bean attributes using direct mappings without any special considerations.
There are some special considerations when using one-to-one mappings (see "One-to-One Mappings and EJB"), one-to-many mappings (see "One-to-Many Mappings and EJB"), and many-to-many mappings (see "Many-to-Many Mappings and EJB").