• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

inserting NULL with iBatis

 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a simple mapping using a parameterClass :
<insert id="insertTest" parameterClass="mypackage.MyClass">
...


I'm not sure how to deal with NULL values in MyClass.
What I do now is using isNotNull and isNull tags like :
<isNotNull property="myproperty">
#myproperty#,
</isNotNull>
<isNull property="myproperty">
NULL,
</isNull>

This is ugly. Is there a better way to deal NULLs ?
I know I could use parameterMap instead of parameterClass but it does not seem to be recommended.
 
Jaikiran Pai
Marshal
Pie
Posts: 10444
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In your MyClass, you could have primitive types for non-nullable fields and object types for nullable fields. Is this what you are looking for?

P.S: I havent used iBatis before, so my answer might be way off mark.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, that's not the problem. But thank you for helping.

I've got it. Specifying the jdbcType after the propertyName will do.
Like #myproperty:VARCHAR#.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic