Use transformation mappings for specialized translations between how a value is represented in Java and in the database.
get
/set
methods of a direct-to-field mapping.Often, a transformation mapping is appropriate when values from multiple fields are used to create an object. This type of mapping requires that you provide an attribute transformation method that is invoked when reading the object from the database. This method must have at least one parameter that is an instance of DatabaseRow
. In your attribute transformation method, you can send the get()
message to the DatabaseRow
to get the value in a specific column. Your attribute transformation method can specify a second parameter, when it is an instance of Session
. The Session
performs queries on the database to get additional values needed in the transformation. The method should return the value to be stored in the attribute.
Transformation mappings also require a field transformation method for each field, to be written to the database when the object is saved. The transformation methods are specified in a dictionary associating each field with a method. The method returns the value to be stored in that field.
Figure 5-14 illustrates a transformation mapping. The values from the B_DATE and B_TIME fields are used to create a java.util.Date
to be stored in the birthDate
attribute.
Figure 5-14 Transformation Mappings
Copyright © 1997, 2004, Oracle. All rights reserved.