There is no statement named student.selectByPrimaryKey in this SqlMap.

liwei3324 2009-09-17 06:27:42
今天下午用abator生成ibatis文件后,运行,老是报下面这个异常。按照网上的方法,还是没解决问题。请大侠指点,多谢了!
Exception in thread "main" com.ibatis.sqlmap.client.SqlMapException: There is no statement named student.selectByPrimaryKey in this SqlMap.
at com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.getMappedStatement(SqlMapExecutorDelegate.java:231)
at com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.queryForObject(SqlMapExecutorDelegate.java:509)
at com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.queryForObject(SqlMapExecutorDelegate.java:493)
at com.ibatis.sqlmap.engine.impl.SqlMapSessionImpl.queryForObject(SqlMapSessionImpl.java:106)
at com.ibatis.sqlmap.engine.impl.SqlMapClientImpl.queryForObject(SqlMapClientImpl.java:82)
at com.sinojp.dao.StudentDAOImpl.selectByPrimaryKey(StudentDAOImpl.java:66)
at com.sinojp.dao.StudentDAOImpl.main(StudentDAOImpl.java:136)
下面是student_SqlMap.xml配置文件,代码如下:
<?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="student" >
<resultMap id="abatorgenerated_StudentResult" class="com.sinojp.domain.Student" >
<result column="id" property="id" jdbcType="INTEGER" />
<result column="name" property="name" jdbcType="VARCHAR" />
</resultMap>
<sql id="Example_Where_Clause" >
<iterate property="oredCriteria" conjunction="or" prepend="where" removeFirstPrepend="iterate" >
<isEqual property="oredCriteria[].valid" compareValue="true" >
(
<iterate prepend="and" property="oredCriteria[].criteriaWithoutValue" conjunction="and" >
$oredCriteria[].criteriaWithoutValue[]$
</iterate>
<iterate prepend="and" property="oredCriteria[].criteriaWithSingleValue" conjunction="and" >
$oredCriteria[].criteriaWithSingleValue[].condition$
#oredCriteria[].criteriaWithSingleValue[].value#
</iterate>
<iterate prepend="and" property="oredCriteria[].criteriaWithListValue" conjunction="and" >
$oredCriteria[].criteriaWithListValue[].condition$
<iterate property="oredCriteria[].criteriaWithListValue[].values" open="(" close=")" conjunction="," >
#oredCriteria[].criteriaWithListValue[].values[]#
</iterate>
</iterate>
<iterate prepend="and" property="oredCriteria[].criteriaWithBetweenValue" conjunction="and" >
$oredCriteria[].criteriaWithBetweenValue[].condition$
#oredCriteria[].criteriaWithBetweenValue[].values[0]# and
#oredCriteria[].criteriaWithBetweenValue[].values[1]#
</iterate>
)
</isEqual>
</iterate>
</sql>
<select id="selectByPrimaryKey" resultMap="StudentResult" parameterClass="com.sinojp.domain.Student" >
select id, name
from student
where id = #id:INTEGER#
</select>
<select id="selectByExample" resultMap="StudentResult" parameterClass="com.sinojp.domain.StudentExample" >
select id, name
from student
<isParameterPresent >
<include refid="student.Example_Where_Clause" />
<isNotNull property="orderByClause" >
order by $orderByClause$
</isNotNull>
</isParameterPresent>
</select>
<delete id="deleteByPrimaryKey" parameterClass="com.sinojp.domain.Student" >
delete from student
where id = #id:INTEGER#
</delete>
<delete id="deleteByExample" parameterClass="com.sinojp.domain.StudentExample" >
delete from student
<include refid="student.Example_Where_Clause" />
</delete>
<insert id="insert" parameterClass="com.sinojp.domain.Student" >
insert into student (name)
values (#name:VARCHAR#)
<selectKey resultClass="java.lang.Integer" keyProperty="id" >
SELECT LAST_INSERT_ID()
</selectKey>
</insert>
<update id="updateByPrimaryKey" parameterClass="com.sinojp.domain.Student" >
update student
set name = #name:VARCHAR#
where id = #id:INTEGER#
</update>
<update id="updateByPrimaryKeySelective" parameterClass="com.sinojp.domain.Student" >
update student
<dynamic prepend="set" >
<isNotNull prepend="," property="name" >
name = #name:VARCHAR#
</isNotNull>
</dynamic>
where id = #id:INTEGER#
</update>
<select id="countByExample" parameterClass="com.sinojp.domain.StudentExample" resultClass="java.lang.Integer" >
select count(*) from student
<include refid="student.Example_Where_Clause" />
</select>
<update id="updateByExampleSelective" >
update student
<dynamic prepend="set" >
<isNotNull prepend="," property="record.id" >
id = #record.id:INTEGER#
</isNotNull>
<isNotNull prepend="," property="record.name" >
name = #record.name:VARCHAR#
</isNotNull>
</dynamic>
<isParameterPresent >
<include refid="student.Example_Where_Clause" />
</isParameterPresent>
</update>
<update id="updateByExample" >
update student
set id = #record.id:INTEGER#,
name = #record.name:VARCHAR#
<isParameterPresent >
<include refid="student.Example_Where_Clause" />
</isParameterPresent>
</update>
</sqlMap>

SqlMapConfig.xml配置文件,代码如下:
<?xml version ="1.0" encoding="UTF-8"?>
<!DOCTYPE sqlMapConfig PUBLIC "-//ibatis.apache.org//DTD SQL Map Config 2.0//EN"
"http://ibatis.apache.org/dtd/sql-map-config-2.dtd">
<sqlMapConfig >
<properties resource="com/sinojp/configuration/SqlMap.properties"/>
<transactionManager type="JDBC">
<dataSource type="SIMPLE">
<property value="${driver}" name="JDBC.Driver"/>
<property value="${url}" name="JDBC.ConnectionURL"/>
<property value="${username}" name="JDBC.Username"/>
<property value="${password}" name="JDBC.Password"/>
</dataSource>
</transactionManager>
<settings useStatementNamespaces="true" /> <sqlMap resource="com/sinojp/configuration/student_SqlMap.xml" />
</sqlMapConfig>
...全文
1978 15 打赏 收藏 转发到动态 举报
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
liwei3324 2011-05-16
  • 打赏
  • 举报
回复
[Quote=引用 14 楼 fei12990 的回复:]
我的怎么还是不可以啊,想楼主请教啊。我没有那个SqlMapConfig.xml文件,而是abator自己生成的abatorConfig.xml。
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE abatorConfiguration PUBLIC "-//Apache Software Foundation//DTD Abator for i……
[/Quote]
abatorConfig.xml应该就相当于SqlMapConfig.xml。不清楚我上面的答案你明白没。你也可以尝试加上
<settings useStatementNamespaces="true"/>。
码上有肉吃 2011-05-09
  • 打赏
  • 举报
回复
我的怎么还是不可以啊,想楼主请教啊。我没有那个SqlMapConfig.xml文件,而是abator自己生成的abatorConfig.xml。
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE abatorConfiguration PUBLIC "-//Apache Software Foundation//DTD Abator for iBATIS Configuration 1.0//EN" "http://ibatis.apache.org/dtd/abator-config_1_0.dtd" >
<abatorConfiguration >
<abatorContext >
<jdbcConnection driverClass="oracle.jdbc.driver.OracleDriver" connectionURL="jdbc:oracle:thin:@localhost:1521:orcl" userId="cuit" password="cuit2012" >
<classPathEntry location="E:\fei\lib\Oracle-11.2.0.1.0-JDBC_ojdbc6.jar" />
</jdbcConnection>
<javaModelGenerator targetPackage="test.model" targetProject="test" />
<sqlMapGenerator targetPackage="test.config" targetProject="test" />
<daoGenerator targetPackage="test.dao" targetProject="test" type="GENERIC-CI" />
<table schema="cuit" tableName="test" >
</table>
</abatorContext>
</abatorConfiguration>

运行的时候也出现了 There is no statement named abatorgenerated_selectByPrimaryKey in this SqlMap.
求解啊~
Longerandlonger 2011-03-30
  • 打赏
  • 举报
回复
这个帖子有用!
玛格尔 2010-09-28
  • 打赏
  • 举报
回复
我的还是不行
玛格尔 2010-09-28
  • 打赏
  • 举报
回复
<sqlMap namespace="User">

<typeAlias alias="User"
type="com.gdret.UserMis.domain.Users"/>

<resultMap id="UserResult" class="User">
<result property="userid" column="USERID"/>
<result property="username" column="USERNAME"/>
<result property="password" column="PASSWORD"/>
<result property="jobno" column="JOBNO"/>
<result property="dept" column="DEPT"/>
<result property="remark" column="REMARK"/>
</resultMap>

<insert id="insertModel" parameterClass="User">
INSERT INTO LTC_USER(USERNAME, PASSWORD, JOBNO,DEPT,REMARK)
VALUES
(

#username#,
#password#,
#jobno#,
#dept#,
#remark#
)
</insert>


<delete id="deleteModel" parameterClass="int">
DELETE LTC_USER WHERE LTC_USER.USERID = #userid#
</delete>

<update id="updateModel" parameterClass="User">
UPDATE LTC_USER SET
USERNAME = #username#,
PASSWORD = #password#,
JOBNO = #jobno#,
DEPT = #dept#,
REMARK = #remark#
WHERE LTC_USER.USERID = #userid#
</update>

<select id="queryModelAll" resultMap="UserResult" >
SELECT * FROM LTC_USER ORDER BY USERID DESC
</select>

<select id="queryModel" resultMap="UserResult" parameterClass="int">
SELECT * FROM LTC_USER WHERE LTC_USER.USERID = #userid#
</select>
</sqlMap>
何勇 2010-08-08
  • 打赏
  • 举报
回复
Thanks
SunlightMan 2010-08-08
  • 打赏
  • 举报
回复
谢谢分享
zzxsun1 2010-07-29
  • 打赏
  • 举报
回复
我的还没有解决
liwei3324 2010-07-29
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 zzxsun1 的回复:]

我的还没有解决
[/Quote]把你的代码贴出来看看。
小洋 2010-01-12
  • 打赏
  • 举报
回复
heheh 谢啦
timeriver_wang 2009-10-15
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 liwei3324 的回复:]
加上 <settings useStatementNamespaces="true"/>[/Quote]
谢了,我的问题也解决了
弘石 2009-09-18
  • 打赏
  • 举报
回复
恩,解决了问题就好,看来楼主解决问题的能力不错
liwei3324 2009-09-18
  • 打赏
  • 举报
回复
谢谢二楼的关注和热心。今天自己已经解决了问题,并找到了真正的原因了。因为我是用abator自动生成所有的文件的。
解决方案:在SqlMapConfig这个配置文件里,加上<settings useStatementNamespaces="true"/>这句话。注意必须是加在properties的下面。否则会报错说,不匹配。
原因:因为用abator自动生成ibatis配置文件时,会带有命名空间。而用SqlMapConfig这个配置文件默认的是不使用命名空间。所以,运行程序,就会报异常:There is no statement named ### in this SqlMap.因此,这个问题其实还有一种解决方案。那就是删除SqlMapConfig配置文件的命名空间,并相应更改sqlMap映射文件中的相关引用。
弘石 2009-09-17
  • 打赏
  • 举报
回复
貌似是配置的SqlMap里少关键字为selectByPrimaryKey的sql语句
Engineast 2009-09-17
  • 打赏
  • 举报
回复
hun

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧