Thursday, July 30, 2009

Ibatis error: Error parsing XPath '/sqlMap/insert'. Cause: java.util.NoSuchElementException

If IBatis is throwing following exception then apart from usual suspects of correct dtd declaration in sql-map-config xml and sql-map xml files, one should also look at the insert sql definition in sql-map xml.

com.ibatis.common.xml.NodeletException: Error parsing XML. Cause: java.lang.RuntimeException: Error parsing XPath '/sqlMapConfig/sqlMap'. Cause: com.ibatis.common.xml.NodeletException: Error parsing XML. Cause: java.lang.RuntimeException: Error parsing XPath '/sqlMap/insert'. Cause: java.util.NoSuchElementException

I had something like this in my insert query xml definition:
INSERT INTO TEST_T (ACCT_ID) VALUES (#acctId)

above mentioned sql statement throws com.ibatis.common.xml.NodeletException which is difficult to figure out.

In my case, error is due to not having closing hash (#) with acctId

If i change the insert statement to following then things work again, notice the closing # in #acctId#

INSERT INTO TEST_T (ACCT_ID) VALUES (#acctId#)

Hope that this is of some use to others who get this error.

10 comments:

Amit said...

thanks it saved my life , amit

Ivan said...

saved my life as well. many thanks

Steve said...

Thanks. I'm converting a myBatis 3 DAO to myBatis 2 for a rare case. myBatis 3 uses a parameter syntax of #{xxx} and myBatis 2 was choking hard with the useless NoSuchElementException. Your post helped me fix my code.

wilson said...

Thanks.. it saved me lots of time

Unknown said...

Thanks....my problem is also solved.now it is working fine..

Anonymous said...

Thanks alot! my problem also solved!

Nitin said...

Thanks a lot, it helped me with my problem.

John said...

I spent almost 2 hours on this, doing all sorts of things until I searched for it and yours is the first on the result. Saved my rest of evening ... :)
Thank you!

Soumya Gattupalli said...

God bless your soul ! You saved me.

Unknown said...

I was spending 2 hours on that already, you saved my night!
I can finally finish my task!