Ibatis Nullpointer calling stored procedure

Today, a collegue of mine had a really strange nullpointer problem trying to call a stored procedure in an Oracle 10 database using iBATIS Java 2.2.0. What she had was a normal JavaBean, like so: 

package com.rolfje.foo
public class BarBean {
    private String barName;
    private Long barId;

    ... setters/getters here ...
}

A straightforward parametermap:

<parameterMap class="com.rolfje.foo.BarBean"
      id="barbeanMap">
   <parameter property="barName" />
   <parameter property="barId" />
</parameterMap>

and a straightforward procedure mapping:

<procedure id="insertBar" parameterMap="barbeanMap">
   {	call store_bar (
      ?,?)
   }
</procedure>

When trying to call the stored procedure, she got the following stacktrace:

org.springframework.jdbc.UncategorizedSQLException: SqlMapClient operation;
uncategorized SQLException for SQL [];
SQL state [null]; error code [0];
--- The error occurred in com/rolfje/foo/sqlmaps/ParameterMap.xml.
--- The error occurred while applying a parameter map.
--- Check the barBeanMap.
--- Check the statement (update procedure failed).
--- Cause: java.lang.NullPointerException; nested exception is

com.ibatis.common.jdbc.exception.NestedSQLException:
--- The error occurred in com/rolfje/foo/sqlmaps/ParameterMap.xml.
--- The error occurred while applying a parameter map.
--- Check the barBeanMap.
--- Check the statement (update procedure failed).
--- Cause: java.lang.NullPointerException
Caused by: java.lang.NullPointerException
Caused by: com.ibatis.common.jdbc.exception.NestedSQLException:
--- The error occurred in com/rolfje/foo/sqlmaps/ParameterMap.xml.
--- The error occurred while applying a parameter map.
--- Check the barBeanMap.
--- Check the statement (update procedure failed).
--- Cause: java.lang.NullPointerException
Caused by: java.lang.NullPointerException
   at ...executeQueryWithCallback(GeneralStatement.java:188)
   at ...executeQueryForObject(GeneralStatement.java:104)
   at ...queryForObject(SqlMapExecutorDelegate.java:565)
...

After hours of staring at the problem, and comparing code with similar constructions from other projects, we decided to switch to the Oracle 9i thin driver to see if that would solve the problem. It didn’t, but there was an interesting development: The Oracle 9i driver actually gave us a decent error about not being able to parse the SQL statement. Which brings us to…

The solution:
We removed all layout from the procedure mapping, which resulted in:

<procedure id="insertBar" parameterMap="barbeanMap">
   {call store_bar (?,?)}
</procedure>

This solved the problem. Then we switched back to the Oracle 10i thin driver, and the problem was still gone. The problem lies in the TAB between the left curly bracket and the word “call”. Oracle can not handle this.To investigate this problem, we then also tried to insert <![CDATA[ ]]> around the procedure call, but as soon as there is a TAB between the { and the word “call” iBATIS will throw a NullPointer. The strange thing is that you can have spaces, newlines and tabs *anywhere* in the procedure mapping, as long as there is no TAB between the left curly and the word “call”.

One Response to Ibatis Nullpointer calling stored procedure

  1. Disgruntled Developer says:

    THANK YOU. I’ve been staring at this problem for over a day. I doubt it would have occurred to me that a freaking tab character would cause the Oracle driver to throw an NPE.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s