Java Reference
In-Depth Information
Table 4.4
Parameter mapping attributes (continued)
The nullValue attribute can be set to any valid value based on property type.
The nullValue attribute is used to specify an outgoing null value replacement. What
this means is that when the value is detected in the JavaBeans property or Map entry,
a NULL will be written to the database (the opposite behavior of an inbound null value
This allows you to use a “magic” null number in your application for types that do not
support null values (e.g., int, double, float, etc.). When these types of properties con-
tain a matching null value (e.g., -9999), a NULL will be written to the database
instead of the value.
This attribute is used exclusively for stored procedure support. It is covered in detail
in section 5.5.2.
If you want to specify a type handler (instead of letting iBATIS select one based on the
javaType and jdbcType attributes), you can do that here.
More commonly, this is used to provide a custom type handler, which will be covered
in chapter 12.
While inline parameter mapping in i BATIS works well for most mapped state-
ments, if you want to improve performance or encounter a case where things are
not working as expected, an external parameter map may be just what you need.
In chapter 5, we will look at a full-blown external parameter map, but for our pur-
poses here, that is not needed.
Inline parameter mapping revisited
In the beginning of section 4.2, we talked about using inline parameter mapping in
its simplest form to tell i BATIS the names of properties that we wanted to substitute
into your query at runtime. In addition to that, you can provide some of the
attributes that external parameter maps allow, such as the database type and a null
value placeholder for your parameters, by separating the parameter name, the
type, and the null value placeholder with colon characters. The database type is
commonly required when you use null-capable columns in your database. The rea-
son for this is that the JDBC API uses this method to send null values to the database:
public void setNull(
int parameterIndex,
int sqlType);
If you do not tell i BATIS what the type is, then it will use java.sql.Types.OTHER for
the second parameter, and some drivers do not allow that (for example, the Ora-
cle driver currently does not) and you will get an error in that case.
Search WWH ::

Custom Search