MyIbatis 3.3.0 and Insert dynamic columns

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

MyIbatis 3.3.0 and Insert dynamic columns

Frodo S
Hi, 

Trying to execute this query:

<insert id="addSolicitudFwd">
    INSERT INTO ACE_OPERACION_FWD
    (ID_ENTIDAD, ID_OPERACION, SENTIDO, PROPUESTA_RIESGOS, CCC,


   
<if  test="sentido.id != null and sentido.id == 'C'">
            NOMINAL_CLIENTE_COMPRA,
     
</if>  
   
<if  test="sentido.id != null and sentido.id == 'V'">
            NOMINAL_CLIENTE_VENDE,  
     
</if>

    )
    VALUES (#{entidad}, #{id}, #{sentido.id}, #{propuesta,typeHandler=PropuestaStringTypeHandler}, #{ccc}, #{nominal})
   
</insert>

But I am getting always this error: java.lang.NumberFormatException: For input string: "V". sentido.id has this value(C or V) but I dont know why is trying to map it to a Number. The property #{nominal} in my JavaBean is double. Which is the right way to insert dynamic columns?

Thanks

--
You received this message because you are subscribed to the Google Groups "mybatis-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: MyIbatis 3.3.0 and Insert dynamic columns

Erwan Letessier
The null check can be removed: if it is C or V then it's not null. Null check should be done prior to call MyBatis.
With 2 ifs you allow building an invalid query that would like to insert 6 bound values into 5 columns. 
Replace with choose-when == C otherwise @see the doc.
Can test with replacing param nominal with hard-coded value to check whether it is the source of the error.
Add a logger with the name of the namespace to see generated sql query.


On Mon, Nov 5, 2018, 18:17 Frodo S <[hidden email] wrote:
Hi, 

Trying to execute this query:

<insert id="addSolicitudFwd">
    INSERT INTO ACE_OPERACION_FWD
    (ID_ENTIDAD, ID_OPERACION, SENTIDO, PROPUESTA_RIESGOS, CCC,


   
<if  test="sentido.id != null and sentido.id == 'C'">
            NOMINAL_CLIENTE_COMPRA,
     
</if>  
   
<if  test="sentido.id != null and sentido.id == 'V'">
            NOMINAL_CLIENTE_VENDE,  
     
</if>

    )
    VALUES (#{entidad}, #{id}, #{sentido.id}, #{propuesta,typeHandler=PropuestaStringTypeHandler}, #{ccc}, #{nominal})
   
</insert>

But I am getting always this error: java.lang.NumberFormatException: For input string: "V". sentido.id has this value(C or V) but I dont know why is trying to map it to a Number. The property #{nominal} in my JavaBean is double. Which is the right way to insert dynamic columns?

Thanks

--
You received this message because you are subscribed to the Google Groups "mybatis-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "mybatis-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: MyIbatis 3.3.0 and Insert dynamic columns

Guy Rouillier-2
In reply to this post by Frodo S
As written, the INSERT statement has a dangling comma issue.  You should be getting a syntax error.

--
Guy Rouillier

------ Original Message ------
From: "Frodo S" <[hidden email]>
To: "mybatis-user" <[hidden email]>
Sent: 11/5/2018 12:17:12 PM
Subject: MyIbatis 3.3.0 and Insert dynamic columns

Hi, 

Trying to execute this query:

<insert id="addSolicitudFwd">
    INSERT INTO ACE_OPERACION_FWD
    (ID_ENTIDAD, ID_OPERACION, SENTIDO, PROPUESTA_RIESGOS, CCC,


   
<if  test="sentido.id != null and sentido.id == 'C'">
            NOMINAL_CLIENTE_COMPRA,
     
</if>  
   
<if  test="sentido.id != null and sentido.id == 'V'">
            NOMINAL_CLIENTE_VENDE,  
     
</if>

    )
    VALUES (#{entidad}, #{id}, #{sentido.id}, #{propuesta,typeHandler=PropuestaStringTypeHandler}, #{ccc}, #{nominal})
   
</insert>

But I am getting always this error: java.lang.NumberFormatException: For input string: "V". sentido.id has this value(C or V) but I dont know why is trying to map it to a Number. The property #{nominal} in my JavaBean is double. Which is the right way to insert dynamic columns?

Thanks

--
You received this message because you are subscribed to the Google Groups "mybatis-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "mybatis-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.