SQL Mapping Files
Harry
· 11 Sep 2026
· 9 views
The Heart of iBATIS
SQL mapping files hold named statements, parameter maps and result maps. They were the pattern MyBatis inherited almost unchanged.
<!DOCTYPE sqlMap PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN"
"http://ibatis.apache.org/dtd/sql-map-2.dtd">
<sqlMap namespace="Customer">
<resultMap id="customerResult" class="com.example.app.domain.Customer">
<result property="id" column="id"/>
<result property="name" column="name"/>
<result property="email" column="email"/>
<result property="city" column="city" nullValue="unknown"/>
</resultMap>
<select id="getCustomer" parameterClass="long" resultMap="customerResult">
SELECT id, name, email, city FROM customers WHERE id = #id#
</select>
<insert id="insertCustomer" parameterClass="com.example.app.domain.Customer">
INSERT INTO customers (name, email, city)
VALUES (#name#, #email#, #city#)
</insert>
<update id="updateCustomer" parameterClass="com.example.app.domain.Customer">
UPDATE customers SET city = #city# WHERE id = #id#
</update>
<delete id="deleteCustomer" parameterClass="long">
DELETE FROM customers WHERE id = #id#
</delete>
</sqlMap>Positional and Named Parameters
iBATIS uses the #property# syntax inside SQL. The framework reads the value from the parameter object (here a Customer) and binds it safely - the ancestor of MyBatis' #{ }.
Key Points
- Mapping files hold select, insert, update and delete statements.
- #property# safely binds values from the parameter object.
- resultMap with column-to-property mapping shapes the objects.
- A namespace prefixes statement ids (Customer.getCustomer).