ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Mkhitaryan, Aram" <Aram.Mkhitar...@lycos-europe.com>
Subject RE: ---- Re: null pointer exception when updating sqlMap
Date Wed, 23 Aug 2006 04:31:43 GMT
Try to use parameter and result maps.

In maps specify sql types and java types.

You may have problem because of you have null and

IBATIS can’t determine the type of the field.

There is the same problem also with plain prepared statements

while setting null values.






From: Sourav Sen [mailto:sourav.sen@kewill.com] 
Sent: Tuesday, August 22, 2006 8:33 PM
To: user-java@ibatis.apache.org
Subject: RE: ---- Re: null pointer exception when updating sqlMap


Hi , 


A normal Javabean with a no-args public constructor and loads of getters and setters. There
must be a way to tell iBatis to ignore nulls 


public class Pkg {


            private Long pkgId;

            private String pkgNum;

            private Long mnfId;

            private Long cgnId;

            private BigDecimal pkgWeightKg;

            private BigDecimal pkgWeightLb;

            private BigDecimal pkgVolumeM3;

            private BigDecimal pkgVolumeC3;

            private BigDecimal pkgValue;



public Pkg() {








             * @return Long


            public Long getCgnId() {

                        return cgnId;



             * @param cgnId


            public void setCgnId(Long cgnId) {

                        this.cgnId = cgnId;










From: Adediran.Ayandele@Sun.COM [mailto:Adediran.Ayandele@Sun.COM] 
Sent: 22 August 2006 16:17
To: user-java@ibatis.apache.org
Subject: ---- Re: null pointer exception when updating sqlMap


What does your Pkg look like?

Sourav Sen wrote: 



It gives me a NullPointerException when trying to update a record that I previously selected
using iBatis SQLMap.

When I selected the record it had some null columns , I set some of them to valid values ,
but during my update

All the other null columns stays as it is . 


Then when I do updatePkg(pkg)


I execute delegate methods that roughly looks like 


try {

            return (ArrayList) sqlMap. queryForList ("getPkgListByConsignmentId ", cgnId);

        } catch (SQLException e) {

            // TODO Auto-generated catch block




Then I enumerate my Pkgs and make some changes based on the context. Finally I try to update
each one with another method that looks like


try {

            sqlMap.update("updatePkg", pkg);

        } catch (SQLException e) {

            // TODO Auto-generated catch block




Which uses

            <statement id="getPkgListByConsignmentId" parameterClass="long"


            select * from kse_pkg where CGN_ID = #cgnId#



<update id="updatePkg"


            UPDATE kse_pkg set pkg_num = #pkgNum#, mnf_id = #mnfId#, cgn_id =#cgnId#, pkg_weight_kg
= #pkgWeightKg#,

                  num_order = #numOrder#, pkg_trk_ref_num = #pkgTrkRefNum# ,  state_id = #stateId#,

                  last_modified_by = #lastModifiedBy#, last_modified_date = #lastModifiedDate#

                  WHERE pkg_id = #pkgId#



<resultMap id="rMapPkgWithOrderItem" class="com.kse.vo.Pkg">

            <result property="mnfId" column="mnf_id" />

            <result property="pkgId" column="pkg_id" />

            <result property="cgnId" column="cgn_id" />

            <result property="pkgNum" column="pkg_num" />

            <result property="stateId" column="state_id" />

            <result property="pkgWeightKg" column="pkg_weight_kg" />

            <result property="pkgWeightLb" column="pkg_weight_lb" />

            <result property="pkgVolumeM3" column="pkg_volume_m3" />

            <result property="pkgVolumeC3" column="pkg_volume_c3" />               

            <result property="numOrder" column="num_order" />



Here if any of the fields like pkgTrkRefNum is null  . I get a NullPointerException.


 I get the same result if I select  the same row using 

<select id="getPkg" parameterClass="int"


            SELECT pkg_id,pkg_num,mnf_id,cgn_id,pkg_weight_kg as pkgWeightKg,pkg_weight_lb
as pkgWeightLb,

            pkg_volume_m3 as pkgVolumeM3 ,pkg_volume_c3 as pkgVolumeC3,pkg_value,num_order,pkg_trk_ref_num
as pkgTrkRefNum,


            FROM kse_pkg WHERE pkg_id = #pkgId#



Any clues ?






View raw message