下载ibatis jPetStore看了一下,的确是个学习的好例子,
我运行了一下,用的是mysql,运行到把产品添加到购物车就报错:
com.ibatis.dao.client.template.SqlMapDaoTemplate.queryForObject
(SqlMapDaoTemplate.java:162)
37 more
Caused by: java.sql.SQLException: Duplicate key or integrity
constraint violation message from server: "Column 'ITEMID' in field
list is ambiguous"
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:1997)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1167)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1278)
at com.mysql.jdbc.Connection.execSQL(Connection.java:2247)
at com.mysql.jdbc.PreparedStatement.execute
(PreparedStatement.java:1371)
at
com.ibatis.sqlmap.engine.execution.SqlExecutor.executeQuery
(SqlExecutor.java:180)
at
com.ibatis.sqlmap.engine.mapping.statement.GeneralStatement.sqlExecut
eQuery(GeneralStatement.java:205)
at
com.ibatis.sqlmap.engine.mapping.statement.GeneralStatement.executeQu
eryWithCallback(GeneralStatement.java:173)
43 more
查了半天原来是配置文件查询的地方有的小错误。
<select id="getItem" resultClass="item" parameterClass="string" cacheModel="quantityCache">
select
//默认里面少了个”I“。。。。。
I . ITEMID,
LISTPRICE,
UNITCOST,
SUPPLIER AS supplierId,
I.PRODUCTID AS "product.productId",
NAME AS "product.name",
DESCN AS "product.description",
CATEGORY AS "product.categoryId",
STATUS,
ATTR1 AS attribute1,
ATTR2 AS attribute2,
ATTR3 AS attribute3,
ATTR4 AS attribute4,
ATTR5 AS attribute5,
QTY AS quantity
from ITEM I, INVENTORY V, PRODUCT P
where P.PRODUCTID = I.PRODUCTID
and I.ITEMID = V.ITEMID
and I.ITEMID = #value#
</select>