aspose file tools*
The moose likes Object Relational Mapping and the fly likes inserting NULL with iBatis Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "inserting NULL with iBatis" Watch "inserting NULL with iBatis" New topic
Author

inserting NULL with iBatis

Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

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.


[My Blog]
All roads lead to JavaRanch
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 10202
    
166

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.


[My Blog] [JavaRanch Journal]
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

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#.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: inserting NULL with iBatis