approaches have their advantages and disadvantages, which are summarized in
Advantages and disadvantages of JavaBeans and Maps as data structures
Strong typing at compile time
Compile-time name checking
Refactoring support in IDE
Less type casting
More code (get/set)
No compile-time check
More runtime errors
No refactoring support
As a general rule, using a bean is the recommended practice for domain data
(i.e., getting an account or order out of the database for editing), whereas using a
Map is recommended for less critical and more dynamic data (i.e., a report or
other output methods).
When creating a result map, if you map a field to a property that does not
exist, you will get an exception immediately when the result map is loaded. This
early failure loading the SQL Map is a good thing, because it means that you catch
the error before your users see it.
On the other hand, if you map a column that does not exist to a property that
does exist, you experience a rather nasty runtime failure when trying to get the
data. This is a good reason to have lots of unit tests around your DAO layer (see
chapter 13 for more of these sorts of best practices with i BATIS ).
In this chapter, we delved into the basics of JavaBeans, the SQL Map API , and map-
ping statements. As you become more familiar with the topics presented here, cre-
ating mapping statements will become as easy as any other development tasks you
perform, and just like anything else, the more you do it, the easier it will be.
If you want to tighten down your application and eliminate as many runtime
errors as possible, be explicit! Use explicit parameter and result maps as well as
strongly typed beans for both parameters and results. This will also make your