You could do two things:

1. Hava a BaseUserVO and FullUserVO that extends BaseUserVO.  Write seperate
result maps and use as appropriate

2. Have UserVO as now, but write two different resultMaps - a base resultMap
and a full resultMap that extends the base resultMap.  Then specify the
appropriate resultMap on the different queries.

I've done both at different times, but sounds like #2 is more appropriate in
your situation.

iBATIS does not support optional attributes now.

Jeff Butler



On 3/15/07, Collin Peters <[EMAIL PROTECTED]> wrote:

The whole point is that I don't want to include the extra SQL fields
at all, and still only have one resultMap class.

In my entire application I only want to ever have one class that
represents a user (called UserVO).  So I would have a sqlmap called
getUser where I pass in an ID and get *all* the details for that user.
Then I have another sqlmap called getAppointments which gets a bunch
of appointments, and all the participants in each appointment.  For
the participants, they can be stored in a UserVO, but I don't want to
retrieve their password and other extraneous fields that aren't
important to being a participant in an appointment.

Currently in iBatis when I specify the participants of an appointment like
this:
       <resultMap id="eventResult" class="EventVO" groupBy="eventID">
               <result property="eventID" column="event_id" />
               <result property="summary" column="summary" />
<snip....>
               <result property="participants" resultMap="userResult" />
       </resultMap>
       <resultMap id="userResult" class="UserVO" >
               <result property="userID" column="user_id"/>
               <result property="password" column="password"/>
<snip...>
       </resultMap>

iBatis will error because I am not including the password in the SQL
to get the appointments.  So my options I see so far are:
- include the extra user fields in the SQL
- create a new object class called ParticipantUserVO without the extra
fields
- any others?

What I was hoping is there was some way to specify a property in a
resultMap as optional.  So that when constructing the object if it
failed to find that column it would simply set it as null and continue
on its merry way instead of failing.  Am I making sense?

On 3/15/07, Larry Meadors <[EMAIL PROTECTED]> wrote:
> You could use dynamic SQL to do that, just make the password '' in the
> cases you don't want it.
>
> <select...>
> select ...
> <isEqual property="showPassword" compareValue="true">password</isEqual>
> <isEqual property="showPassword" compareValue="false">'' as
password</isEqual>
> ...
> </select>
>
> Larry
>
>
> On 3/15/07, Collin Peters <[EMAIL PROTECTED]> wrote:
> > Hi everyone,
> >
> > I'm just wondering if it is possible to have an optional property in a
> > resultMap?  For example, I have a UserVO class which I use to load
> > users into.  It has fields such as user_id, username, firstname,
> > lastname, password, etc...  I also want to use this class as a
> > 'sub'-resultMap from another call.  For example, I have a call called
> > loadDailySchedule, in this call I grab all events in a schedule, along
> > with all the participants, and group by the event_id.  So the sqlmap
> > is:
> >
> >         <resultMap id="eventResult" class="EventVO" groupBy="eventID">
> >                 <result property="eventID" column="event_id" />
> >                 <result property="summary" column="summary" />
> > <snip...>
> >                 <result property="participants" resultMap="
common.userResult" />
> >         </resultMap>
> >
> > The problem is that I don't want to have to include fields like the
> > users password in this query as it is not needed.  If I want to use
> > the common.userResult resultMap (which uses the UserVO class) though,
> > I need to include those fields otherwise I get the error: "The column
> > name password was not found in this ResultSet"
> >
> > Regards,
> > Collin
> >
>

Reply via email to