Attribute "nameSpace" must be declared for element type "sqlMap".
2009-09-15 16:10
447 查看
在学习ibatis的时候遇到的异常
你可能写了多个orm配置文件,每个配置文件里都进行一些CRUD之类的操作,难免会遇到两个或者多个配置文件中的都有一个statement的id命名为 find***,
<statement id="findById" parameterClass="java.lang.Integer" resultMap="BookMap">
<statement id="findById" parameterClass="java..lang.Integer" resultMap="PubMap">
在使用getSqlMapClient().update("findById", id)的时候,findById到底是那个orm里的呢?
测试的过程中会出现异常:
Exception in thread "main" java.lang.RuntimeException: Error occurred. Cause: 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: org.xml.sax.SAXParseException: Attribute "nameSpace" must be declared for element type "sqlMap".
这就引入了一个命名空间(Namespaces),为了以示区别,就在ibatis的核心配置文件中配置一个节点
<sqlMapConfig>
<settings useStatementNamespaces="true" lazyLoadingEnabled="true"/>
<sqlMap resource=".......
再在你的orm配置文件中将根节点修改为<sqlMap namespace="Book">
把测试语句改为getSqlMapClient().update("Book.findById", id) 即可。
你可能写了多个orm配置文件,每个配置文件里都进行一些CRUD之类的操作,难免会遇到两个或者多个配置文件中的都有一个statement的id命名为 find***,
<statement id="findById" parameterClass="java.lang.Integer" resultMap="BookMap">
<statement id="findById" parameterClass="java..lang.Integer" resultMap="PubMap">
在使用getSqlMapClient().update("findById", id)的时候,findById到底是那个orm里的呢?
测试的过程中会出现异常:
Exception in thread "main" java.lang.RuntimeException: Error occurred. Cause: 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: org.xml.sax.SAXParseException: Attribute "nameSpace" must be declared for element type "sqlMap".
这就引入了一个命名空间(Namespaces),为了以示区别,就在ibatis的核心配置文件中配置一个节点
<sqlMapConfig>
<settings useStatementNamespaces="true" lazyLoadingEnabled="true"/>
<sqlMap resource=".......
再在你的orm配置文件中将根节点修改为<sqlMap namespace="Book">
把测试语句改为getSqlMapClient().update("Book.findById", id) 即可。
相关文章推荐
- ERROR [ValidatorFileParser] Attribute "short-circuit" must be declared forelement type "field-validator".
- Attribute "resultClass" must be declared for element type "insert".
- Attribute "scope" must be declared for element type "bean"
- web.xml中的web-app中出现Attribute "xsi:schemaLocation" must be declared for element type "web-app".
- Attribute "resultClass" must be declared for element type "insert".
- Attribute "resultType" must be declared for element type "insert"或"update"
- Attribute "resource" must be declared for element type "mapper".
- 【hibernate】Attribute "column" must be declared for element type "property"解决办法
- FAQ(4):Attribute "resource" must be declared for element type "mapper".
- Attribute "resultType" must be declared for element type "update" or "insert"
- Attribute "statementType" must be declared for element type "procedure"
- 【hibernate】Attribute "column" must be declared for element type "property"解决办法
- Attribute "scope" must be declared for element type "bean"
- Attribute "column" must be declared for element type "property"解决办法
- Attribute "scope" must be declared for element type "bean"-[spring]
- Attribute "column" must be declared for element type "property"解决办法
- Attribute "resultType" must be declared for element type "insert".
- Attribute "column" must be declared for element type "property"解决办法
- Attribute "resultCalss" must be declared for element type "select".
- [报错]Attribute "xmlns:xsi" must be declared for element type "web-app"