Insert with inner bind elements does not work

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

Insert with inner bind elements does not work

Frodo S
Hi, 

Trying to do the next : 

<insert id="addOperacionFwd" parameterType="OperacionFwd" >
 
 
<bind name="sentido" value="sentido.toString()"/>  
 
<bind name="fxSwapDataPataLarga.sentido" value="fxSwapDataPataLarga.sentido.toString()"/>

 
  INSERT INTO ACE_OPERACION_FWD  
        ( SENTIDO, SENTIDO_SWAP)  
         VALUES
          (#{sentido},#{fxSwapDataPataLarga.sentido}  )      
   
 
</insert>




What I get is:

org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.type.TypeException: Could not set parameters for mapping: ParameterMapping{property='fxSwapDataPataLarga.sentido', mode=IN, javaType=class com.isb.acelera.domain.SideSpotFwd, jdbcType=null, numericScale=null, resultMapId='null', jdbcTypeName='null', expression='null'}. Cause: org.apache.ibatis.type.TypeException: Error setting non null for parameter #44 with JdbcType null . Try setting a different JdbcType for this parameter or a different configuration property. Cause: java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Enum


sentido and fxSwapDataPataLarga.sentido are both enums and before inserting them into dabatase, I call toString() method in both. The curious thing is it works with property sentido but not with the inner property fxSwapDataPataLarga.sentido. Any clues?

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: Insert with inner bind elements does not work

Iwao AVE!

Hi Frodo,

Does the enum override toString() method?
If not, you wouldn’t need <bind />s at all as the built-in EnumTypeHandler calls name() method which yields the same result as toString().

In case you actually need the result of toString() method, you should use variable names that do not contain dots (with dots, a nested map object is created) and, preferably, are distinguishable from the property names to avoid confusion.

<bind name="v1" value="sentido.toString()"/>  
<bind name="v2" value="fxSwapDataPataLarga.sentido.toString()"/>
...
VALUES (#{v1}, #{v2})

Also, if you always want to use toString() instead of name(), it would be better to write a custom enum type handler rather than writing <bind />s repeatedly.
Search ‘defaultEnumTypeHandler’ in the doc : http://www.mybatis.org/mybatis-3/configuration.html

Regards,
Iwao


On Sun, Dec 9, 2018 at 2:38 AM Frodo S <[hidden email]> wrote:
Hi, 

Trying to do the next : 

<insert id="addOperacionFwd" parameterType="OperacionFwd" >
 
 
<bind name="sentido" value="sentido.toString()"/>  
 
<bind name="fxSwapDataPataLarga.sentido" value="fxSwapDataPataLarga.sentido.toString()"/>

 
  INSERT INTO ACE_OPERACION_FWD  
        ( SENTIDO, SENTIDO_SWAP)  
         VALUES
          (#{sentido},#{fxSwapDataPataLarga.sentido}  )      
   
 
</insert>




What I get is:

org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.type.TypeException: Could not set parameters for mapping: ParameterMapping{property='fxSwapDataPataLarga.sentido', mode=IN, javaType=class com.isb.acelera.domain.SideSpotFwd, jdbcType=null, numericScale=null, resultMapId='null', jdbcTypeName='null', expression='null'}. Cause: org.apache.ibatis.type.TypeException: Error setting non null for parameter #44 with JdbcType null . Try setting a different JdbcType for this parameter or a different configuration property. Cause: java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Enum


sentido and fxSwapDataPataLarga.sentido are both enums and before inserting them into dabatase, I call toString() method in both. The curious thing is it works with property sentido but not with the inner property fxSwapDataPataLarga.sentido. Any clues?

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.