You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user-java@ibatis.apache.org by Alexandre Nunes <am...@gmail.com> on 2004/12/20 21:16:09 UTC
Relationship Mapping
Hi,
i'd like to know how do i map a relationship using iBatis.
For example, i have an object "Item" wich has a "Product", so i have
the following:
class Item {
private Long id;
private Product product;
private Long productId;
// ... all the getters and setters....
}
class Product {
private Long id;
private String name;
// ... all the getters and setters....
}
So i have a SqlMap for each other....
<resultMap id="itemResult" class="item">
<result property="id" column="ITEM_ID"/>
<result property="description" column="ITEM_DESCRIPTION"/>
<result property="productId" column="PRODUCT_ID"/>
<result property="product.id" column="PRODUCT_ID"/>
<result property="product.name" column="PRODUCT_NAME"/>
</resultMap>
<resultMap id="productResult" class="product">
<result property="id" column="PRODUCT_ID"/>
<result property="name" column="PRODUCT_NAME"/>
</resultMap>
My question is:
- For every relationship, do i have to re-wrte the mapping,
constructing the relationed object (product, in the example)? Or
iBatis has a way to reuse the product mapping, already wrote?
It's like call the "Product Mapping" from the "Item Mapping", when i
have to construct a Product.
Regards.