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//E开发者_如何学CN" "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.
I hope that you have specified the contactus.xml file which contains insert statement in the SqlMapConfig.xml as below
<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>
Call without namespace.Something like below
sqlMapper.insert("ibatorgenerated_insert",params);
Try adding the following to your <sqlMapConfig>
element:
<settings useStatementNamespaces="true"/>
精彩评论