You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user-java@ibatis.apache.org by dandante <da...@dandante.com> on 2008/01/07 21:54:20 UTC

problem returning primitive types from a query

In my bean I have the following properties defined along with their
corresponding getters and setters:

int ownerId;
boolean isPrivate;

In my result map I map these columns as follows:
       <result property="ownerId" column="owner_id" jdbcType="int"
javaType="int"/>
       <result property="private" column="is_private" jdbcType="BIT"
javaType="boolean"/>

Then I run a query that returns this result map. I get the following error:
java.lang.RuntimeException:
com.ibatis.common.jdbc.exception.NestedSQLException:  --- The error occurred
in org/systemsbiology/GWAP/domain/Condition.xml. --- The error occurred
while applying a result map. --- Check the
Condition.ConditionGroupWithConditionsResultMap. --- The error happened
while setting a property on the result object. --- Cause:
net.sf.cglib.beans.BulkBeanException
[...]

If I change the bean to use wrapper types (Integer and Boolean) it works
fine. But I would rather use primitive types.

Hope you can help.

Also, will the next version of IBATIS be java 1.5+ compatible? If so, would
this issue be resolved by boxing and unboxing?

Thanks 
-- 
View this message in context: http://www.nabble.com/problem-returning-primitive-types-from-a-query-tp14675618p14675618.html
Sent from the iBATIS - User - Java mailing list archive at Nabble.com.


Re: problem returning primitive types from a query

Posted by Nathan Maves <na...@gmail.com>.
I agree with Larry on this one.  IB already supports autoboxing.  The real
issue here is why do you have nulls in a column that is represented by a
primitive?  If the column is null what would you expect your returned value
to be as an int/boolean?

On a second note....

Why such a push to use a primitive?  In the real world 99% of the data
returned from a DB is mutable and hence there is really no performance gains
by using a primitive.

Nathan

On Jan 7, 2008 3:08 PM, Larry Meadors <lm...@apache.org> wrote:

> I'm guessing the values in the database are null. If they are, the
> result map types have to be wrapped - you can't represent null in a
> primitive, even with boxing.
>
> If that is not adequate, your other option is to make the SQL provide
> a default value for null values.
>
> Larry
>
>
> On Jan 7, 2008 1:54 PM, dandante <da...@dandante.com> wrote:
> >
> > In my bean I have the following properties defined along with their
> > corresponding getters and setters:
> >
> > int ownerId;
> > boolean isPrivate;
> >
> > In my result map I map these columns as follows:
> >        <result property="ownerId" column="owner_id" jdbcType="int"
> > javaType="int"/>
> >        <result property="private" column="is_private" jdbcType="BIT"
> > javaType="boolean"/>
> >
> > Then I run a query that returns this result map. I get the following
> error:
> > java.lang.RuntimeException:
> > com.ibatis.common.jdbc.exception.NestedSQLException:  --- The error
> occurred
> > in org/systemsbiology/GWAP/domain/Condition.xml. --- The error occurred
> > while applying a result map. --- Check the
> > Condition.ConditionGroupWithConditionsResultMap. --- The error happened
> > while setting a property on the result object. --- Cause:
> > net.sf.cglib.beans.BulkBeanException
> > [...]
> >
> > If I change the bean to use wrapper types (Integer and Boolean) it works
> > fine. But I would rather use primitive types.
> >
> > Hope you can help.
> >
> > Also, will the next version of IBATIS be java 1.5+ compatible? If so,
> would
> > this issue be resolved by boxing and unboxing?
> >
> > Thanks
> > --
> > View this message in context:
> http://www.nabble.com/problem-returning-primitive-types-from-a-query-tp14675618p14675618.html
> > Sent from the iBATIS - User - Java mailing list archive at Nabble.com.
> >
> >
>

Re: problem returning primitive types from a query

Posted by Larry Meadors <lm...@apache.org>.
I'm guessing the values in the database are null. If they are, the
result map types have to be wrapped - you can't represent null in a
primitive, even with boxing.

If that is not adequate, your other option is to make the SQL provide
a default value for null values.

Larry


On Jan 7, 2008 1:54 PM, dandante <da...@dandante.com> wrote:
>
> In my bean I have the following properties defined along with their
> corresponding getters and setters:
>
> int ownerId;
> boolean isPrivate;
>
> In my result map I map these columns as follows:
>        <result property="ownerId" column="owner_id" jdbcType="int"
> javaType="int"/>
>        <result property="private" column="is_private" jdbcType="BIT"
> javaType="boolean"/>
>
> Then I run a query that returns this result map. I get the following error:
> java.lang.RuntimeException:
> com.ibatis.common.jdbc.exception.NestedSQLException:  --- The error occurred
> in org/systemsbiology/GWAP/domain/Condition.xml. --- The error occurred
> while applying a result map. --- Check the
> Condition.ConditionGroupWithConditionsResultMap. --- The error happened
> while setting a property on the result object. --- Cause:
> net.sf.cglib.beans.BulkBeanException
> [...]
>
> If I change the bean to use wrapper types (Integer and Boolean) it works
> fine. But I would rather use primitive types.
>
> Hope you can help.
>
> Also, will the next version of IBATIS be java 1.5+ compatible? If so, would
> this issue be resolved by boxing and unboxing?
>
> Thanks
> --
> View this message in context: http://www.nabble.com/problem-returning-primitive-types-from-a-query-tp14675618p14675618.html
> Sent from the iBATIS - User - Java mailing list archive at Nabble.com.
>
>