ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Larry Meadors" <lmead...@apache.org>
Subject Re: troubleshooting selectKey
Date Mon, 29 Jan 2007 12:31:47 GMT
Are you sure you are calling insert() and not update()?

Larry


On 1/29/07, Robert Campbell <rrc7cz@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;
>     }
> ...
>

Mime
View raw message