Java Reference
In-Depth Information
4.4 Using inline and explicit result maps
Inline result maps are great, because they are super easy to use, and in most cases
work well enough.
Explicit result maps are also valuable in i BATIS because they provide higher
performance, tighter configuration validation, and more precise behavior. When
using explicit result mapping, there are very few surprises at runtime. Table 4.5
describes the attributes available for explicit result maps.
Table 4.5
Result map attributes
Attribute
Description
The property attribute of the result map is the name of a JavaBean property or Map
entry of the result object that will be returned by the mapped statement.
The name can be used more than once depending on the number of times it is needed
to populate the results.
property
The column attribute is used to provide the name of the column in the ResultSet
that will be used to populate the property.
column
columnIndex As an optional (minimal) performance enhancement, the columnIndex attribute can
be used to provide the index of the column in the ResultSet instead of the column
name.
This is not likely necessary in 99 percent of applications and sacrifices maintainability
and readability for performance. Depending on your JDBC driver, you may or may not
experience any performance increase.
The jdbcType attribute is used to explicitly specify the database column type of the
ResultSet column that will be used to populate the property.
Although result maps do not have the same difficulties with null values as parameter
maps do, specifying the type can be useful for certain mapping types, such as Date
properties.
Because Java only has one Date value type and SQL databases may have many (usu-
ally at least three), specifying the date may become necessary in some cases to
ensure that dates (or other types) are set correctly.
Similarly, a VARCHAR, CHAR, or CLOB may populate String types, so specifying the
type might be needed in those cases too.
Depending on your driver, you may not need to set this attribute.
jdbcType
javaType
The javaType attribute is used to explicitly specify the Java property type of the prop-
erty to be set. Normally this can be derived from a JavaBeans property through reflec-
tion, but certain mappings such as Map and XML mappings cannot provide the type to
the framework.
If the javaType is not set and the framework cannot otherwise determine the type,
the type is assumed to be Object.
Search WWH ::




Custom Search