2011-04-08 41 views
3

我正在嘗試使用iBatis插入一些用戶在聯繫我們窗體中發送的數據。爲什麼在插入數據時收到SqlMapException?

我正在使用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

我希望您所指定的contactus.xml文件,其中包含在SqlMapConfig.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); 
+0

是的你說得對,以前我在我的XML文件中有'',並認爲我可以將配置添加到同一個文件中。現在,當試圖插入數據時,我得到一個'NullPointerException',但它看起來像一個新問題 - 所以我會創建一個新的問題! :P – 2011-04-19 08:26:46

1

嘗試添加以下到您的<sqlMapConfig>元素:

<settings useStatementNamespaces="true"/> 
相關問題