Way to set a field as required in resultMap

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Way to set a field as required in resultMap

Bryan
Is there a way to set a field as required in a resultMap definition? I
have found myself on occasion adding a field to a resultMap but
forgetting to add it to one of the queries that uses it. I would like
for Mybatis to throw an exception or something if the field defined in
a resultMap does not exist in the result set.

For example, say I have this result map:

<resultMap id="testResultMap" type="com.foobar.Test">
  <id property="id" column="id" jdbcType="VARCHAR" />
  <result property="enabled" column="enabled" jdbcType="BOOLEAN" />
</resultMap>

and this query:

<select id="getAllTests" resultMap="testResultMap">
  select id from test
</select>

Is there a way to tell Mybatis to throw an exception because the
"enabled" field was missing from the result set?

Reply | Threaded
Open this post in threaded view
|

Re: Way to set a field as required in resultMap

Nathan Maves
This is really where your unit test of your mapper should catch these
types of mistakes.

On Wed, Oct 20, 2010 at 2:48 PM, Bryan <[hidden email]> wrote:

> Is there a way to set a field as required in a resultMap definition? I
> have found myself on occasion adding a field to a resultMap but
> forgetting to add it to one of the queries that uses it. I would like
> for Mybatis to throw an exception or something if the field defined in
> a resultMap does not exist in the result set.
>
> For example, say I have this result map:
>
> <resultMap id="testResultMap" type="com.foobar.Test">
>  <id property="id" column="id" jdbcType="VARCHAR" />
>  <result property="enabled" column="enabled" jdbcType="BOOLEAN" />
> </resultMap>
>
> and this query:
>
> <select id="getAllTests" resultMap="testResultMap">
>  select id from test
> </select>
>
> Is there a way to tell Mybatis to throw an exception because the
> "enabled" field was missing from the result set?
>
>
Reply | Threaded
Open this post in threaded view
|

Re: Way to set a field as required in resultMap

Bryan
Agreed, I have many unit tests, but it would make the unit tests more
effective if Mybatis could catch issues like this. For example, in the
scenario above, "enabled" will simply be set to the default (e.g.
false). This may or may not be correct, depending on the data. Writing
tests for each case like this would become very tedious.

On Oct 20, 1:55 pm, Nathan Maves <[hidden email]> wrote:

> This is really where your unit test of your mapper should catch these
> types of mistakes.
>
>
>
>
>
>
>
> On Wed, Oct 20, 2010 at 2:48 PM, Bryan <[hidden email]> wrote:
> > Is there a way to set a field as required in a resultMap definition? I
> > have found myself on occasion adding a field to a resultMap but
> > forgetting to add it to one of the queries that uses it. I would like
> > for Mybatis to throw an exception or something if the field defined in
> > a resultMap does not exist in the result set.
>
> > For example, say I have this result map:
>
> > <resultMap id="testResultMap" type="com.foobar.Test">
> >  <id property="id" column="id" jdbcType="VARCHAR" />
> >  <result property="enabled" column="enabled" jdbcType="BOOLEAN" />
> > </resultMap>
>
> > and this query:
>
> > <select id="getAllTests" resultMap="testResultMap">
> >  select id from test
> > </select>
>
> > Is there a way to tell Mybatis to throw an exception because the
> > "enabled" field was missing from the result set?
Reply | Threaded
Open this post in threaded view
|

RE: Way to set a field as required in resultMap

Rick.Wellman
Doesn't iBatis 2.3.0+ throw just such an exception?  That's the version we are using and I could swear it does (coming from a 43yr old with probable early-onset alzheimers)

-----Original Message-----
From: [hidden email] [mailto:[hidden email]] On Behalf Of Bryan
Sent: Wednesday, October 20, 2010 4:05 PM
To: mybatis-user
Subject: Re: Way to set a field as required in resultMap

Agreed, I have many unit tests, but it would make the unit tests more
effective if Mybatis could catch issues like this. For example, in the
scenario above, "enabled" will simply be set to the default (e.g.
false). This may or may not be correct, depending on the data. Writing
tests for each case like this would become very tedious.

On Oct 20, 1:55 pm, Nathan Maves <[hidden email]> wrote:

> This is really where your unit test of your mapper should catch these
> types of mistakes.
>
>
>
>
>
>
>
> On Wed, Oct 20, 2010 at 2:48 PM, Bryan <[hidden email]> wrote:
> > Is there a way to set a field as required in a resultMap definition? I
> > have found myself on occasion adding a field to a resultMap but
> > forgetting to add it to one of the queries that uses it. I would like
> > for Mybatis to throw an exception or something if the field defined in
> > a resultMap does not exist in the result set.
>
> > For example, say I have this result map:
>
> > <resultMap id="testResultMap" type="com.foobar.Test">
> >  <id property="id" column="id" jdbcType="VARCHAR" />
> >  <result property="enabled" column="enabled" jdbcType="BOOLEAN" />
> > </resultMap>
>
> > and this query:
>
> > <select id="getAllTests" resultMap="testResultMap">
> >  select id from test
> > </select>
>
> > Is there a way to tell Mybatis to throw an exception because the
> > "enabled" field was missing from the result set?
Reply | Threaded
Open this post in threaded view
|

Re: Way to set a field as required in resultMap

Larry Meadors
As a fellow geezer, I agree - I think it does.

On Wed, Oct 20, 2010 at 3:16 PM, Rick.Wellman <[hidden email]> wrote:

> Doesn't iBatis 2.3.0+ throw just such an exception?  That's the version we are using and I could swear it does (coming from a 43yr old with probable early-onset alzheimers)
>
> -----Original Message-----
> From: [hidden email] [mailto:[hidden email]] On Behalf Of Bryan
> Sent: Wednesday, October 20, 2010 4:05 PM
> To: mybatis-user
> Subject: Re: Way to set a field as required in resultMap
>
> Agreed, I have many unit tests, but it would make the unit tests more
> effective if Mybatis could catch issues like this. For example, in the
> scenario above, "enabled" will simply be set to the default (e.g.
> false). This may or may not be correct, depending on the data. Writing
> tests for each case like this would become very tedious.
>
> On Oct 20, 1:55 pm, Nathan Maves <[hidden email]> wrote:
>> This is really where your unit test of your mapper should catch these
>> types of mistakes.
>>
>>
>>
>>
>>
>>
>>
>> On Wed, Oct 20, 2010 at 2:48 PM, Bryan <[hidden email]> wrote:
>> > Is there a way to set a field as required in a resultMap definition? I
>> > have found myself on occasion adding a field to a resultMap but
>> > forgetting to add it to one of the queries that uses it. I would like
>> > for Mybatis to throw an exception or something if the field defined in
>> > a resultMap does not exist in the result set.
>>
>> > For example, say I have this result map:
>>
>> > <resultMap id="testResultMap" type="com.foobar.Test">
>> >  <id property="id" column="id" jdbcType="VARCHAR" />
>> >  <result property="enabled" column="enabled" jdbcType="BOOLEAN" />
>> > </resultMap>
>>
>> > and this query:
>>
>> > <select id="getAllTests" resultMap="testResultMap">
>> >  select id from test
>> > </select>
>>
>> > Is there a way to tell Mybatis to throw an exception because the
>> > "enabled" field was missing from the result set?
>
Reply | Threaded
Open this post in threaded view
|

RE: Way to set a field as required in resultMap

Rick.Wellman
So, I guess that begs the question why MyBatis has a different behavior?

-----Original Message-----
From: [hidden email] [mailto:[hidden email]] On Behalf Of Larry Meadors
Sent: Wednesday, October 20, 2010 4:29 PM
To: [hidden email]
Subject: Re: Way to set a field as required in resultMap

As a fellow geezer, I agree - I think it does.

On Wed, Oct 20, 2010 at 3:16 PM, Rick.Wellman <[hidden email]> wrote:

> Doesn't iBatis 2.3.0+ throw just such an exception?  That's the version we are using and I could swear it does (coming from a 43yr old with probable early-onset alzheimers)
>
> -----Original Message-----
> From: [hidden email] [mailto:[hidden email]] On Behalf Of Bryan
> Sent: Wednesday, October 20, 2010 4:05 PM
> To: mybatis-user
> Subject: Re: Way to set a field as required in resultMap
>
> Agreed, I have many unit tests, but it would make the unit tests more
> effective if Mybatis could catch issues like this. For example, in the
> scenario above, "enabled" will simply be set to the default (e.g.
> false). This may or may not be correct, depending on the data. Writing
> tests for each case like this would become very tedious.
>
> On Oct 20, 1:55 pm, Nathan Maves <[hidden email]> wrote:
>> This is really where your unit test of your mapper should catch these
>> types of mistakes.
>>
>>
>>
>>
>>
>>
>>
>> On Wed, Oct 20, 2010 at 2:48 PM, Bryan <[hidden email]> wrote:
>> > Is there a way to set a field as required in a resultMap definition? I
>> > have found myself on occasion adding a field to a resultMap but
>> > forgetting to add it to one of the queries that uses it. I would like
>> > for Mybatis to throw an exception or something if the field defined in
>> > a resultMap does not exist in the result set.
>>
>> > For example, say I have this result map:
>>
>> > <resultMap id="testResultMap" type="com.foobar.Test">
>> >  <id property="id" column="id" jdbcType="VARCHAR" />
>> >  <result property="enabled" column="enabled" jdbcType="BOOLEAN" />
>> > </resultMap>
>>
>> > and this query:
>>
>> > <select id="getAllTests" resultMap="testResultMap">
>> >  select id from test
>> > </select>
>>
>> > Is there a way to tell Mybatis to throw an exception because the
>> > "enabled" field was missing from the result set?
>