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 Robert Campbell <rr...@gmail.com> on 2007/01/29 11:41:21 UTC

troubleshooting selectKey

I've used iBatis for a while, and selectKey without trouble. For some
reason, however, the following code won't work. It never calls setId() on
the object passed in as a parameter. Basically i'm getting an Oracle error
telling me id can't be null.. so selectKey isn't calling setId() before the
Insert as it should. Any ideas? Thanks everyone!

    <insert id="addUser" parameterClass="credential">
        <selectKey resultClass="java.lang.Long" keyProperty="id" type="pre">
            select gw_sequence.nextval as id from dual
        </selectKey>
        <![CDATA[
            insert into credentials (
                id,
                username,
                password,
                organization_id
            ) values (
                #id#,
                #username#,
                #password#,
                #organizationId#
            )
        ]]>
    </insert>

Model:

....

    protected Long id;

    /**
     * @return Returns the id.
     */
    public Long getId() {
        log.error("******************* User.getId() returned " + id);
        return id;
    }

    /**
     * @param id
     *            The id to set.
     */
    public void setId(Long id) {
        log.error("******************* User.setId() set to " + id);
        this.id = id;
    }
...

Re: troubleshooting selectKey

Posted by Robert Campbell <rr...@gmail.com>.
That was it! Damn copy-paste bites me in the ass again. Thank you VERY much!


On 1/29/07, Larry Meadors <lm...@apache.org> wrote:
>
> Are you sure you are calling insert() and not update()?
>
> Larry
>
>
> On 1/29/07, Robert Campbell <rr...@gmail.com> wrote:
> > I've used iBatis for a while, and selectKey without trouble. For some
> > reason, however, the following code won't work. It never calls setId()
> on
> > the object passed in as a parameter. Basically i'm getting an Oracle
> error
> > telling me id can't be null.. so selectKey isn't calling setId() before
> the
> > Insert as it should. Any ideas? Thanks everyone!
> >
> >     <insert id="addUser" parameterClass="credential">
> >         <selectKey resultClass="java.lang.Long" keyProperty="id"
> type="pre">
> >             select gw_sequence.nextval as id from dual
> >         </selectKey>
> >         <![CDATA[
> >             insert into credentials (
> >                 id,
> >                 username,
> >                 password,
> >                 organization_id
> >             ) values (
> >                 #id#,
> >                 #username#,
> >                 #password#,
> >                 #organizationId#
> >             )
> >         ]]>
> >     </insert>
> >
> > Model:
> >
> > ....
> >
> >     protected Long id;
> >
> >     /**
> >      * @return Returns the id.
> >      */
> >     public Long getId() {
> >         log.error("******************* User.getId() returned " + id);
> >         return id;
> >     }
> >
> >     /**
> >      * @param id
> >      *            The id to set.
> >      */
> >     public void setId(Long id) {
> >         log.error("******************* User.setId() set to " + id);
> >         this.id = id;
> >     }
> > ...
> >
>

Re: troubleshooting selectKey

Posted by Larry Meadors <lm...@apache.org>.
Are you sure you are calling insert() and not update()?

Larry


On 1/29/07, Robert Campbell <rr...@gmail.com> wrote:
> I've used iBatis for a while, and selectKey without trouble. For some
> reason, however, the following code won't work. It never calls setId() on
> the object passed in as a parameter. Basically i'm getting an Oracle error
> telling me id can't be null.. so selectKey isn't calling setId() before the
> Insert as it should. Any ideas? Thanks everyone!
>
>     <insert id="addUser" parameterClass="credential">
>         <selectKey resultClass="java.lang.Long" keyProperty="id" type="pre">
>             select gw_sequence.nextval as id from dual
>         </selectKey>
>         <![CDATA[
>             insert into credentials (
>                 id,
>                 username,
>                 password,
>                 organization_id
>             ) values (
>                 #id#,
>                 #username#,
>                 #password#,
>                 #organizationId#
>             )
>         ]]>
>     </insert>
>
> Model:
>
> ....
>
>     protected Long id;
>
>     /**
>      * @return Returns the id.
>      */
>     public Long getId() {
>         log.error("******************* User.getId() returned " + id);
>         return id;
>     }
>
>     /**
>      * @param id
>      *            The id to set.
>      */
>     public void setId(Long id) {
>         log.error("******************* User.setId() set to " + id);
>         this.id = id;
>     }
> ...
>