ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jeff Butler <jeffgbut...@gmail.com>
Subject Re: Selective Update of fields depending on values in object
Date Thu, 16 Feb 2006 13:59:42 GMT
Rashmi has correctly identified the core problem - sometimes you want a
column to be null, and sometimes you want to ignore the column.  The only
way I can think to solve the problem is to have a seperate set of indictors
that denote whther you want to ignore the field in the update or not.  Has
anyone thought of a bettter way?  It should be pretty easy to generate this
with Abator.

Jeff Butler


On 2/16/06, Rashmi Dave <rashmid@persistent.co.in> wrote:
>
>  Thanks so much for this Thomas. However, the problem here is that what if
> the value of a column needs to be null intentionally? This will not work in
> that case. And unfortunately, there is a very high likelihood of this
> happening in my application.
>
>
>
> ~Rashmi
>
>
>  ------------------------------
>
> *From:* Wible, Thomas E [mailto:Thomas.E.Wible@mdnt.com]
> *Sent:* Thursday, February 16, 2006 6:15 PM
> *To:* Rashmi Dave
> *Cc:* user-java@ibatis.apache.org
> *Subject:* RE: Selective Update of fields depending on values in object
>
>
>
> while my predecessor didn't grok the difference between $delimiter$ &
> #delimiter#, he did come up with exactly what u r looking 4:
>
>
>
> <sqlmap>
>
>
>
>  <resultmap id='parameter' class='my.param.obj'>
>
>     <result property='id'        column='id'>
>
>     <result property='name' column='name'>
>
>     <result property='date'   column='date'>
>
>     <result property='value'   column='value'>
>
> ...
>
>  </resultmap>
>
>
>
> <update id='updateParam' parameterClass='my.param.obj'>
>
>     UPDATE paramTable SET
>
>         <dynamic>
>
>             <isNotNull prepend="," property="name">
>
>                 name = $name$
>
>             </isNotNull>
>
>             <isNotNull prepend="," property="date">
>
>                 date = $date$
>
>             </isNotNull>
>
>             <isNotNull prepend="," property="value">
>
>                 value= $value$
>
>             </isNotNull>
>
>         </dynamic>
>
>     WHERE id = $id$
>
>  </update>
>
>
>
> when i've added columns, i've had to use the # delimiter, but the above
> works just fine 4 me;-)
>

Mime
View raw message