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 Chris Berry <ch...@gmail.com> on 2006/07/04 16:10:11 UTC

When requires a TypeHandlers...

Greetings,
I am using iBatis coupled with Axis. This is a great combination. Axis
generates "XMLBeans" for the Request/Response, and I map them directly
into SQLMaps using iBatis. Thus, very little code is required.

Axis tends to wrap primitives (from the XSD) in it's own types (e.g.
UnsignedLong). This is not normally a problem, except when dealing
with keys.

Can someone please explain how to use a TypeHandler with <selectkey>??
It seems that <selectkey> needs the ability to add a TypeHandler??
(BTW: I also tried this unsuccessfully with a <parameterMap>, but I
always got an "index out of range" error)

Thanks,
-- Chris

Details follow...

When I use the following  (for MySQL)

  <insert id="insertBlogEntryMySQL" parameterClass="blogEntryClass" >
    insert into Blog (Name, Title, Text) values (#name#, #title#, #text#)

    <selectKey keyProperty="id"
resultClass="org.apache.axis.types.UnsignedLong" >
      select LAST_INSERT_ID()
    </selectKey>
  </insert>

I get a NullPointerException.
If I use resultClass="int", I get an IllegalArgumentException

Where blogEntryClass contains the following (generated by Axis)

   public class BlogEntry_t  implements java.io.Serializable {
   .....
    public org.apache.axis.types.UnsignedLong getId() {
        return id;
    }
    public void setId(org.apache.axis.types.UnsignedLong id) {
        this.id = id;
    }
    .....

NOTE: if I do it all "manually" -- calling "select LAST_INSERT_ID()"
in a separate <select> and call setId( new UnsignedLong( id )) -- then
it all works great...

Thanks,
-- Chris