4

我正在尝试使用 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 生成的 sql 映射确实包含一个插入查询,其 id 为“ibatorgenerated_insert”,命名空间为“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 文件中找不到该语句?我假设它正在查找文件,因为它没有报告任何其他类型的错误。

4

2 回答 2

5

我希望您在SqlMapConfig.xml中指定了包含插入语句的contactus.xml文件,如下所示

<sqlMapConfig>
    <properties resource="Connection.properties"/>
    <!-- Configure a built-in transaction manager.  If you're using an        app server, you probably want to use its transaction manager        and a managed datasource -->
<settings cacheModelsEnabled="false" enhancementEnabled="true"
  lazyLoadingEnabled="true" maxRequests="32" maxSessions="1"
    useStatementNamespaces="false" />
  <transactionManager type="JDBC">
    <dataSource type="JNDI">
        <property name="DataSource" value="${connection.datasource}"/>
    </dataSource>
  </transactionManager>
 <!-- List the SQL Map XML files. They can be loaded from the        classpath, as they are here (com.domain.data...) -->
    <sqlMap resource="contactus.xml"/>
</sqlMapConfig>

在没有命名空间的情况下调用。如下所示

sqlMapper.insert("ibatorgenerated_insert",params);
于 2011-04-08T14:59:17.987 回答
1

尝试将以下内容添加到您的<sqlMapConfig>元素中:

<settings useStatementNamespaces="true"/>
于 2011-04-08T14:45:48.050 回答