ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Alexandre Nunes <amartinsnu...@gmail.com>
Subject Relationship Mapping
Date Mon, 20 Dec 2004 20:16:09 GMT
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.

Mime
View raw message