ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From joeweder <joewe...@gmail.com>
Subject Cant reuse resultMaps when I have column aliases
Date Fri, 12 Dec 2008 18:11:24 GMT

When I define a resultMap for an object, I'd like to do that once and reuse
it everywhere in my application. The problem I have is that for some queries
the column names are not the same and so I wind up having to make another
resultMap using the column-alias names.

This comes up a lot when I use joins. It came up again and I'd really like
to hear from the community if there is a solution. I have "iBatis in
Action", been looking thru the docs, and google... am I missing something?

Take a look at my example below and please suggest, Thanks in advance.

In the example, I have a message object that contains two contacts (sender
and recipient); this means two joins and aliases for the columns. It would
be cool to somehow reuse a single result map passing in a "prefix".

    <resultMap id="senderResultMap" class="contact">
        <result property="id" column="sid"/>
        <result property="name" column="sname"/>
        <result property="emailAddress" column="semailaddress"/>
        <result property="phoneNumber" column="sphonenumber"/>

    <resultMap id="recipientResultMap" class="contact">
        <result property="id" column="rid"/>
        <result property="name" column="rname"/>
        <result property="emailAddress" column="remailaddress"/>
        <result property="phoneNumber" column="rphonenumber"/>

    <resultMap id="messageResultMap" class="message">
        <result property="id" column="id"/>
        <result property="sender" resultMap="Messages.senderResultMap"/>
        <result property="recipient"
        <result property="subject" column="subject"/>
        <result property="content" column="content"/>

    <select id="findAll" resultMap="messageResultMap">
            sender.id sid, sender.name sname, sender.emailaddress
semailaddress, sender.phonenumber  sphonenumber,
            recipient.id rid, recipient.name rname, recipient.emailaddress
remailaddress, recipient.phonenumber rphonenumber,
            subject, content
        from messages m
        left join contacts sender on m.sender = sender.id
        left join contacts recipient on m.recipient = recipient.id

View this message in context: http://www.nabble.com/Cant-reuse-resultMaps-when-I-have-column-aliases-tp20980742p20980742.html
Sent from the iBATIS - User - Java mailing list archive at Nabble.com.

View raw message