2009年3月26日星期四

用Ibator生成的SalMap与spring集成时的问题

第一、我很傻不知道spring2.5与ibatis2.3集成时,不知道要加ibatis的jar包进去,导致一个异常半小时才觉悟解决好。
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlMapClient' defined in file [E:\WorkSpace\ibator\dataAccessContext.xml]: Instantiation of bean failed; nested exception is java.lang.NoClassDefFoundError: com/ibatis/common/xml/NodeletException

我还debug了呢,以为发现了spring的bug,汗。。。。。

第二、用ibator生成的sqlmap,假设在namespace为account的情况下,下面所有的sql , select,insert,etc 的id 都会加上 account.****。 Junit4测试的时候报异常:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlMapClient' defined in file [E:\WorkSpace\ibator\dataAccessContext.xml]:
Invocation of init method failed; nested exception is org.springframework.core.NestedIOException:
Failed to parse config resource: file [E:\WorkSpace\ibator\sql-map-config.xml];
nested exception is 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/select'.
Cause: java.lang.RuntimeException: Could not find SQL statement to include with refid 'account.ibatorgenerated_Example_Where_Clause'

本以为Ibator是完全可以信赖的,看上去也没什么不对,AccountDaoImpl里面的也对应的很好,是不是ibatis里面那个地方可以设置呢?
在这里我就把namespace,account. 全部删掉,修改AccountDaoImpl。测试后全绿的!

1 条评论:

JT 说...

Please add this to work around this namespace issue inside sql map config xml file -

***sqlMapConfig***
***settings useStatementNamespaces="true"/***
... (your mapping here as usual)

***/sqlMapConfig***