IIRC, insert returns the result of the selectKey query, not your
inserted bean, however that bean that you passed in has the property
set on it.

So you can just do "return wu;" instead.

Larry


On 2/11/07, Rich Garabedian <[EMAIL PROTECTED]> wrote:




I've been spinning my wheels this weekend over something I just know is
stupid.



I have a simple table that I'm trying to do an insert into. The insert
succeeds (I see the row in the database), but my app keeps throwing a



      java.lang.ClassCastException: java.lang.Integer



in the method where I call SqlMapClient.insert(). My database is postgreSQL
and my table has a serial id. Also note that I can load the table just fine.
My config looks like this:



    <resultMap id="WebUserResultMap"
class="com.autorevenue.commands.WebUser">

        <result property="id"              column="id"
jdbcType="INTEGER"/>

        <result property="reasonId"        column="reason_id"
jdbcType="INTEGER"/>

        <result property="logonLimit"      column="login_limit"
jdbcType="INTEGER"/>

        <result property="logonCount"      column="login_count"
jdbcType="INTEGER"/>

        <result property="email"           column="email"
jdbcType="VARCHAR"/>

        <result property="firstName"       column="fname"
jdbcType="VARCHAR"/>

        <result property="password"        column="password"
jdbcType="VARCHAR"/>

        <result property="lastName"        column="lname"
jdbcType="VARCHAR"/>

        <result property="companyName"     column="company_name"
jdbcType="VARCHAR"/>

        <result property="phone"           column="phone"
jdbcType="VARCHAR"/>

        <result property="phoneExt"        column="phone_ext"
jdbcType="VARCHAR"/>

        <result property="approved"        column="approved"
jdbcType="BOOLEAN"/>

        <result property="removed"         column="removed"
jdbcType="BOOLEAN"/>

        <result property="created"         column="create_stamp"
jdbcType="TIMESTAMP"/>

    </resultMap>



The insert config looks like this:



    <!-- SQL statments -->

    <insert id = "InsertWebUser" parameterClass =
"com.mydomain.commands.WebUser">

        <selectKey keyProperty="id" resultClass="int" type="pre">

            SELECT nextVal('web_user_id_seq') as id

        </selectKey>

        insert into web_user (id,  email, reason_id, fname, lname,
company_name, phone, phone_ext, fax) VALUES

                             (#id#, #email#, #reasonId#, #firstName#,
#lastName#, #companyName#, #phone#, #phoneExt#, #fax#)

    </insert>



The WebUser bean is backed by Integer objects instead of int. The last line
my stack trace is (where it says the error is occurring) is as follows:



return (WebUser) _sqlMap.insert ("InsertWebUser", wu);



The last lines in my debug output look fine, and as I said before the insert
works.



11-02-07 16:22:34 DEBUG [http-8080-Processor23]: {pstm-100006} Parameters:
[1663, [EMAIL PROTECTED], 9, Rich, Doe, MyCompany, 9999999999, 123,
1131234567]

11-02-07 16:22:34 DEBUG [http-8080-Processor23]: {pstm-100006} Types:
[java.lang.Integer, java.lang.String, java.lang.Integer, java.lang.String,
java.lang.String, java.lang.String, java.lang.String, java.lang.String,
java.lang.String]



Pretty frustrated … thanks in advance for any advice.

Reply via email to