浏览 6722 次
锁定老帖子 主题:sping+ibatis集成开发时出错
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
|
|
---|---|
作者 | 正文 |
发表时间:2007-09-07
com.ibatis.sqlmap.client.SqlMapException: There is no statement named getUser in this SqlMap. at com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.getMappedStatement(SqlMapExecutorDelegate.java:293) at com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.queryForObject(SqlMapExecutorDelegate.java:557) at com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.queryForObject(SqlMapExecutorDelegate.java:541) at com.ibatis.sqlmap.engine.impl.SqlMapSessionImpl.queryForObject(SqlMapSessionImpl.java:106) at org.springframework.orm.ibatis.SqlMapClientTemplate$1.doInSqlMapClient(SqlMapClientTemplate.java:210) at org.springframework.orm.ibatis.SqlMapClientTemplate.execute(SqlMapClientTemplate.java:168) at org.springframework.orm.ibatis.SqlMapClientTemplate.queryForObject(SqlMapClientTemplate.java:208) at com.tom.test.ibatis.dao.ibatis.UserDaoIbatis.getUser(Unknown Source) at com.tom.test.ibatis.service.impl.UserServiceImpl.getUser(Unknown Source) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:585) at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:287) at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:181) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:148) at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:170) at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:176) at $Proxy1.getUser(Unknown Source) 我的代码如下: UserDaoIbatis.java的代码如下 public class UserDaoIbatis extends BaseDao implements UserDao { public User getUser(Integer id){ return (User) this.getSqlMapClientTemplate().queryForObject( "getUser", id); } public Collection getUsers(){ return this.getSqlMapClientTemplate().queryForList("getAllObjects", null); } public void saveUser(User user) throws DataAccessException { this.getSqlMapClientTemplate().insert("insertObject", user); } } User.java的代码如下 public class User extends BaseBean{ /** * */ private static final long serialVersionUID = 1L; private Integer Id; private String userName; private String userInfo; public Integer getId() { return Id; } public void setId(Integer id) { Id = id; } public String getUserInfo() { return userInfo; } public void setUserInfo(String userInfo) { this.userInfo = userInfo; } public String getUserName() { return userName; } public void setUserName(String userName) { this.userName = userName; } } 我的几个配置文件 applicationContext-ibatis.xml的配置如下 <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd"> <beans> <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="locations"> <list> <value>WEB-INF/classes/config.properties</value> </list> </property> </bean> <!--Init datasource--> <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close"> <property name="driverClass"> <value>${c3p0.driverClass}</value> </property> <property name="jdbcUrl"> <value>${c3p0.jdbcUrl}</value> </property> <property name="user"> <value>${c3p0.user}</value> </property> <property name="password"> <value>${c3p0.password}</value> </property> <property name="initialPoolSize"> <value>${c3p0.initialPoolSize}</value> </property> <property name="minPoolSize"> <value>${c3p0.minPoolSize}</value> </property> <property name="maxPoolSize"> <value>${c3p0.maxPoolSize}</value> </property> <property name="acquireIncrement"> <value>${c3p0.acquireIncrement}</value> </property> <property name="maxIdleTime"> <value>${c3p0.maxIdleTime}</value> </property> <property name="maxStatements"> <value>${c3p0.maxStatements}</value> </property> </bean> <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <property name="dataSource"><ref bean="dataSource"/></property> </bean> <bean id="sqlMapClient" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean"> <property name="configLocation" ><value>classpath:com/tom/test/ibatis/dao/ibatis/sql-map-config.xml</value></property> </bean> <bean id="dao" class="com.tom.test.ibatis.basedao.BaseDao"> <property name="dataSource"><ref bean="dataSource"/></property> <property name="sqlMapClient"><ref local="sqlMapClient"/></property> </bean> <bean id="userDao" class="com.tom.test.ibatis.dao.ibatis.UserDaoIbatis"> <property name="dataSource"><ref bean="dataSource"/></property> <property name="sqlMapClient"><ref local="sqlMapClient"/></property> </bean> </beans> sql-map-config.xml的配置如下 <?xml version="1.0" encoding="UTF-8" standalone="no"?> <!DOCTYPE sqlMapConfig PUBLIC "-//iBATIS.com//DTD SQL Map Config 2.0//EN" "http://www.ibatis.com/dtd/sql-map-config-2.dtd"> <sqlMapConfig> <settings enhancementEnabled="true" maxTransactions="10" maxRequests="128" maxSessions="20"/> <sqlMap resource="com/tom/test/ibatis/bean/User.xml"/> </sqlMapConfig> User.xml的配置如下 <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE sqlMap PUBLIC "-//iBATIS.com//DTD SQL Map 2.0//EN" "http://www.ibatis.com/dtd/sql-map-2.dtd"> <sql-map namespace="User"> <typeAlias alias="User" type="com.tom.test.ibatis.bean.User"/> <result-map name="UserResult" class="User"> <property name="Id" column="id"/> <property name="userName" column="user_name"/> <property name="userInfo" column="user_info"/> </result-map> <insert id="insertObject" parameterClass="User"> insert into user ( id, user_name, user_info, values ( #Id#, #userName#, #userInfo# ) </insert> <select id="getAllObjects" resultMap="UserResult"> select * from user </select> <select id="getUser" parameterClass="Integer" resultClass="User"> select id as Id, user_name as userName, user_info as userInfo from user where id = #value# </select> </sql-map> 声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|
返回顶楼 | |
发表时间:2007-09-07
这种错误还问,用这个User.getUser
|
|
返回顶楼 | |
发表时间:2007-09-07
确认配置文件对不对?
there is no statement named getUser in this SqlMap |
|
返回顶楼 | |
发表时间:2007-09-07
neptune 写道 这种错误还问,用这个User.getUser
用User.getUser最后的错误都是一样的 |
|
返回顶楼 | |
发表时间:2007-09-07
不需要 User.getUser 。因为并没有设置useStatementNamespaces,而useStatementNamespaces默认是false。
你再贴看看BaseDao的代码下。 |
|
返回顶楼 | |
发表时间:2007-09-07
好了
我把sqlMap改了下面是代码 <?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"> <sqlMap namespace="UserSql"> <typeAlias alias="user" type="com.tom.test.ibatis.bean.User"/> <resultMap id="result" class="user"> <result property="id" column="id"/> <result property="userName" column="user_name"/> <result property="userInfo" column="user_info"/> </resultMap> <insert id="insertObject" parameterClass="user"> insert into user (user_name,user_info) values (#userName#, #userInfo#) <selectKey resultClass="int" keyProperty="id" > SELECT @@IDENTITY AS ID </selectKey> </insert> <select id="getUser" parameterClass="int" resultClass="user"> select id as id, user_name as userName, user_info as userInfo from user where id = #value# </select> <select id="getObjects" resultMap="result"> select * from user </select> </sqlMap> |
|
返回顶楼 | |