• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

inserting NULL with iBatis

 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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#.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic