|
|
Platform: Tomcat, MySQL 5.X, Mybatis 3.X
I had a result map like this...
<resultMap type="Inventory" id="inventoryResult">
<result column="owner_id" property="ownerID" />
<result column="available_units" property="unitCount"/>
<result column="product_id" property="productID"/>
<result column="branch_id" property="branchID"/>
</resultMap>
Reading Mybatis 3.X documentation says its advisable to have an <id>
for the resultmap to increase performance.
The SQL I have has 3 joins making the unique id for the result to be a
combination of {owner_id, product_id, branch_id}.
How do I define the <id> in the result map for this scenario ?
I have modified my sql to stringify and concat the 3 IDs like the
following.. but I am not sure if its good of bad.
I would like to know what others have done for a similar scenario.
select concat(convert(m.owner_id, char(32)),convert(p.product_id,
char(32)), ,convert(c.branch_id, char(32))) as id
from inventory i
...
My resultmap now looks like this...
<resultMap type="Inventory" id="inventoryResult">
<id column="id" property="id" />
<result column="owner_id" property="ownerID" />
<result column="available_units" property="unitCount"/>
<result column="product_id" property="productID"/>
<result column="branch_id" property="branchID"/>
</resultMap>
|