为什么我在插入数据时收到 SqlMapException?
我正在尝试使用 iBatis 插入用户在“联系我们”表单中发送的一些数据。
我正在使用 Liferay/Spring MVC/iBatis/MySQL 设置,但我认为问题是由 iBatis 配置引起的。每当我尝试插入数据时,我都会在日志中看到异常:
com.ibatis.sqlmap.client.SqlMapException: There is no statement named contactus.ibatorgenerated_insert in this SqlMap.
at com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.getMappedStatement(SqlMapExecutorDelegate.java:231)
at com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.insert(SqlMapExecutorDelegate.java:367)
at com.ibatis.sqlmap.engine.impl.SqlMapSessionImpl.insert(SqlMapSessionImpl.java:82)
at com.ibatis.sqlmap.engine.impl.SqlMapClientImpl.insert(SqlMapClientImpl.java:58)
ibator generated sql map does contains an insert query with id "ibator generated_insert" with namespace "contact_us"
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE sqlMap PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN" "http://ibatis.apache.org/dtd/sql-map-2.dtd">
<sqlMapConfig>
<sqlMap namespace="contactus">
<insert id="ibatorgenerated_insert" parameterClass="contactUs.dao.ContactUs">
<!--
WARNING - This element is automatically generated by Apache iBATIS ibator, do not modify.
This element was generated on Thu Apr 07 15:17:57 BST 2011.
-->
insert into contactus (email_address, first_name, last_name, company, timestamp,
status, message)
values (#emailAddress:VARCHAR#, #firstName:VARCHAR#, #lastName:VARCHAR#, #company:VARCHAR#,
#timestamp:TIMESTAMP#, #status:VARCHAR#, #message:LONGVARCHAR#)
<selectKey resultClass="java.lang.Integer" keyProperty="contactusId">
SELECT LAST_INSERT_ID()
</selectKey>
</insert>
</sqlMap>
</sqlMapConfig>
是什么导致 iBatis 找不到XML 文件中的声明?我认为它正在找到该文件,因为它没有报告任何其他类型的错误。
I'm trying to use iBatis to insert some data that get sent by a user in a contact us form.
I'm using a Liferay/Spring MVC/iBatis/MySQL setup but I think the problem is caused by the iBatis configuration. Whenever I try to insert data I see an exception in the logs:
com.ibatis.sqlmap.client.SqlMapException: There is no statement named contactus.ibatorgenerated_insert in this SqlMap.
at com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.getMappedStatement(SqlMapExecutorDelegate.java:231)
at com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.insert(SqlMapExecutorDelegate.java:367)
at com.ibatis.sqlmap.engine.impl.SqlMapSessionImpl.insert(SqlMapSessionImpl.java:82)
at com.ibatis.sqlmap.engine.impl.SqlMapClientImpl.insert(SqlMapClientImpl.java:58)
The ibator generated sql map does contain an insert query with id "ibatorgenerated_insert" with namespace "contact_us"
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE sqlMap PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN" "http://ibatis.apache.org/dtd/sql-map-2.dtd">
<sqlMapConfig>
<sqlMap namespace="contactus">
<insert id="ibatorgenerated_insert" parameterClass="contactUs.dao.ContactUs">
<!--
WARNING - This element is automatically generated by Apache iBATIS ibator, do not modify.
This element was generated on Thu Apr 07 15:17:57 BST 2011.
-->
insert into contactus (email_address, first_name, last_name, company, timestamp,
status, message)
values (#emailAddress:VARCHAR#, #firstName:VARCHAR#, #lastName:VARCHAR#, #company:VARCHAR#,
#timestamp:TIMESTAMP#, #status:VARCHAR#, #message:LONGVARCHAR#)
<selectKey resultClass="java.lang.Integer" keyProperty="contactusId">
SELECT LAST_INSERT_ID()
</selectKey>
</insert>
</sqlMap>
</sqlMapConfig>
What can be causing iBatis not to find the statement in the XML file? I assume that it's finding the file since it doesn't report any other kind of error.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我希望您已指定 contactus.xml 文件,其中包含 SqlMapConfig.xml 中的插入语句,如下所示:
没有命名空间的调用。如下所示
I hope that you have specified the contactus.xml file which contains insert statement in the SqlMapConfig.xml as below
Call without namespace.Something like below
尝试将以下内容添加到您的
元素中:Try adding the following to your
<sqlMapConfig>
element: