If the columns returned by a SQL statement match the result object, you may not need an explicit Result Map. If you have control over the relational schema, you might be able to name the columns so they also work as property names. In the following example, the column names and property names already match, so a result map is not needed.
Another way to skip a result map is to use column aliasing to make the column names match the properties names, as shown in the following example.
Of course, these techniques will not work if you need to specify a column type, a null value, or any other property attributes.
Many times, we don't need to return an object with multiple properties. We just need a string, integer, boolean, and so forth. If you don't need to populate an object, SQLMap can return one of the primitive types instead. If you just need the value, you can use a primitive type as a result class, as shown in following example.
Instead of a rich object, sometimes all you might need is a simple key/value list of the data, where each property is an entry on the list. If so, Result Maps can populate an array instance as easily as property objects. The syntax for using an array is identical to the rich object syntax. As shown in following example, only the result object changes.
In the above example, an array instance would be created for each row in the result set and populated with the Product data. The property name attributes, like id, code, and so forth, would be the key of the entry, and the value of the mapped columns would be the value of the entry.
As shown in the following example, you can also use an implicit Result Map with an array type.
What set of entries is returned by the above example depends on what columns are in the result set. If the set of column changes (because columns are added or removed), the new set of entries would automatically be returned.