| Oracle® TopLink Developer's Guide 10g (10.1.3.1.0) B28218-01 |
|
![]() Previous |
![]() Next |
This section introduces direct mapping concepts unique to TopLink, including the following:
The direction of a relationship may be either unidirectional or bidirectional. In a unidirectional relationship, only one entity bean has a relationship field that refers to the other. 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.
In a bidirectional relationship, each entity bean has a relationship field that refers to the other bean. Through the relationship field, an entity bean's code can access its related object. To implement a bidirectional relationship (classes that reference each other), use two unidirectional mappings with the sources and targets reversed.
|
Note: Maintenance of bidirectional relationships presents a number of technical challenges. For more information, see the following: |
You can store object attributes directly in a database table as follows:
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 33-2 summarizes these changes.
Table 33-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 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").
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").