新年新气象,庆祝。待我试用。
作者给出的这个n+1 select解决方案,是针对一对多的,他认为一对一内联类属性的映射,通过视图select和lazyload,已经可以方便地解决,所以着重解决的是1:M / M:N的问题,我拿jpetstore中的表作为例子,如下:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE sqlMap PUBLIC "-//iBATIS.com//DTD SQL Map 2.0//EN" "http://www.ibatis.com/dtd/sql-map-2.dtd">
<sqlMap namespace="Category">
<typeAlias alias="product" type="org.chage.test.ibatis209.Product"/>
<typeAlias alias="category" type="org.chage.test.ibatis209.Category"/>
<resultMap id="categoryResult" class="category" groupBy="categoryId">
<result property="categoryId" column="CATID"/>
<result property="name" column="NAME"/>
<result property="description" column="DESCN"/>
<result property="productList" resultMap="Category.productResult"/>
</resultMap>
<resultMap id="productResult" class="product">
<result property="productId" column="PRODUCTID"/>
<result property="categoryId" column="CATEGORY"/>
<result property="name" column="NAME"/>
<result property="description" column="DESCN"/>
</resultMap>
<select id="getAllCategory" resultMap="categoryResult">
select * from CATEGORY c,product p where c.CATID = p.CATEGORY
</select>
</sqlMap>
注意两处蓝色的部分. 子属性级的resultMap命名空间一定得加上,不然报错。
另外的几个新特性还没有看,直觉得1:m问题最急,因为这个影响比较大,大家说ibatis都知道有个n+1查询问题悬而未决,心理影响比较大。