我下了这个例子,如果用默认的hsqldb,一切ok,如果换成mysql,点击任何一个宠物加到购物车的时候,都会报同一个错:Stack
org.apache.struts.beanaction.BeanActionException: Error dispatching bean action via URL pattern ('addItemToCart'). Cause: org.apache.struts.beanaction.BeanActionException: Error invoking Action. Cause: java.lang.reflect.InvocationTargetException
at org.apache.struts.beanaction.BeanAction.execute(BeanAction.java:249)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:419)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:224)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1194)
at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:414)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:172)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:433)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:174)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:873)
at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:689)
at java.lang.Thread.run(Thread.java:619)
Caused by: org.apache.struts.beanaction.BeanActionException: Error invoking Action. Cause: java.lang.reflect.InvocationTargetException
at org.apache.struts.beanaction.ActionInvoker.invoke(ActionInvoker.java:18)
at org.apache.struts.beanaction.DefaultActionInterceptor.intercept(DefaultActionInterceptor.java:5)
at org.apache.struts.beanaction.BeanAction.execute(BeanAction.java:246)
... 21 more
Caused by: java.lang.reflect.InvocationTargetException
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:597)
at org.apache.struts.beanaction.ActionInvoker.invoke(ActionInvoker.java:16)
... 23 more
Caused by: com.ibatis.dao.client.DaoException: Failed to execute queryForObject - id [getItem], parameterObject [EST-4]. Cause: com.ibatis.common.jdbc.exception.NestedSQLException:
--- The error occurred in com/ibatis/jpetstore/persistence/sqlmapdao/sql/Item.xml.
--- The error occurred while applying a parameter map.
--- Check the getItem-InlineParameterMap.
--- Check the statement (query failed).
--- Cause: com.mysql.jdbc.exceptions.MySQLIntegrityConstraintViolationException: Column 'ITEMID' in field list is ambiguous
Caused by: com.mysql.jdbc.exceptions.MySQLIntegrityConstraintViolationException: Column 'ITEMID' in field list is ambiguous
Caused by: com.ibatis.common.jdbc.exception.NestedSQLException:
--- The error occurred in com/ibatis/jpetstore/persistence/sqlmapdao/sql/Item.xml.
--- The error occurred while applying a parameter map.
--- Check the getItem-InlineParameterMap.
--- Check the statement (query failed).
--- Cause: com.mysql.jdbc.exceptions.MySQLIntegrityConstraintViolationException: Column 'ITEMID' in field list is ambiguous
Caused by: com.mysql.jdbc.exceptions.MySQLIntegrityConstraintViolationException: Column 'ITEMID' in field list is ambiguous
at com.ibatis.dao.client.template.SqlMapDaoTemplate.queryForObject(SqlMapDaoTemplate.java:164)
at com.ibatis.jpetstore.persistence.sqlmapdao.ItemSqlMapDao.getItem(ItemSqlMapDao.java:42)
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:597)
at com.ibatis.dao.engine.impl.DaoProxy.invoke(DaoProxy.java:72)
at $Proxy7.getItem(Unknown Source)
at com.ibatis.jpetstore.service.CatalogService.getItem(CatalogService.java:59)
at com.ibatis.jpetstore.presentation.CartBean.addItemToCart(CartBean.java:60)
... 28 more
Caused by: com.ibatis.common.jdbc.exception.NestedSQLException:
--- The error occurred in com/ibatis/jpetstore/persistence/sqlmapdao/sql/Item.xml.
--- The error occurred while applying a parameter map.
--- Check the getItem-InlineParameterMap.
--- Check the statement (query failed).
--- Cause: com.mysql.jdbc.exceptions.MySQLIntegrityConstraintViolationException: Column 'ITEMID' in field list is ambiguous
Caused by: com.mysql.jdbc.exceptions.MySQLIntegrityConstraintViolationException: Column 'ITEMID' in field list is ambiguous
at com.ibatis.sqlmap.engine.mapping.statement.GeneralStatement.executeQueryWithCallback(GeneralStatement.java:185)
at com.ibatis.sqlmap.engine.mapping.statement.GeneralStatement.executeQueryForObject(GeneralStatement.java:104)
at com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.queryForObject(SqlMapExecutorDelegate.java:561)
at com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.queryForObject(SqlMapExecutorDelegate.java:536)
at com.ibatis.sqlmap.engine.impl.SqlMapSessionImpl.queryForObject(SqlMapSessionImpl.java:93)
at com.ibatis.sqlmap.engine.impl.SqlMapClientImpl.queryForObject(SqlMapClientImpl.java:70)
at com.ibatis.dao.client.template.SqlMapDaoTemplate.queryForObject(SqlMapDaoTemplate.java:162)
... 37 more
Caused by: com.mysql.jdbc.exceptions.MySQLIntegrityConstraintViolationException: Column 'ITEMID' in field list is ambiguous
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:931)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2985)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1631)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1723)
at com.mysql.jdbc.Connection.execSQL(Connection.java:3256)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1313)
at com.mysql.jdbc.PreparedStatement.execute(PreparedStatement.java:874)
at com.ibatis.sqlmap.engine.execution.SqlExecutor.executeQuery(SqlExecutor.java:180)
at com.ibatis.sqlmap.engine.mapping.statement.GeneralStatement.sqlExecuteQuery(GeneralStatement.java:205)
at com.ibatis.sqlmap.engine.mapping.statement.GeneralStatement.executeQueryWithCallback(GeneralStatement.java:173)
... 43 more找到那里的代码: public Item getItem(String itemId) {
Integer i = (Integer) queryForObject("getInventoryQuantity", itemId);
Item item = (Item) queryForObject("getItem", itemId);
item.setQuantity(i.intValue());
return item;
}相应的sql:<select id="getInventoryQuantity" resultClass="int" parameterClass="string">
SELECT QTY AS value
FROM INVENTORY
WHERE ITEMID = #itemId#
</select>
这不可能有错吧,最简单的一种sql了,居然说itemid混淆了,真晕,官网只有基于ibatis2的例子。
另外,有没有关于ibatis比较好的论坛?问题都没处问去。
org.apache.struts.beanaction.BeanActionException: Error dispatching bean action via URL pattern ('addItemToCart'). Cause: org.apache.struts.beanaction.BeanActionException: Error invoking Action. Cause: java.lang.reflect.InvocationTargetException
at org.apache.struts.beanaction.BeanAction.execute(BeanAction.java:249)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:419)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:224)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1194)
at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:414)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:172)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:433)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:174)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:873)
at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:689)
at java.lang.Thread.run(Thread.java:619)
Caused by: org.apache.struts.beanaction.BeanActionException: Error invoking Action. Cause: java.lang.reflect.InvocationTargetException
at org.apache.struts.beanaction.ActionInvoker.invoke(ActionInvoker.java:18)
at org.apache.struts.beanaction.DefaultActionInterceptor.intercept(DefaultActionInterceptor.java:5)
at org.apache.struts.beanaction.BeanAction.execute(BeanAction.java:246)
... 21 more
Caused by: java.lang.reflect.InvocationTargetException
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:597)
at org.apache.struts.beanaction.ActionInvoker.invoke(ActionInvoker.java:16)
... 23 more
Caused by: com.ibatis.dao.client.DaoException: Failed to execute queryForObject - id [getItem], parameterObject [EST-4]. Cause: com.ibatis.common.jdbc.exception.NestedSQLException:
--- The error occurred in com/ibatis/jpetstore/persistence/sqlmapdao/sql/Item.xml.
--- The error occurred while applying a parameter map.
--- Check the getItem-InlineParameterMap.
--- Check the statement (query failed).
--- Cause: com.mysql.jdbc.exceptions.MySQLIntegrityConstraintViolationException: Column 'ITEMID' in field list is ambiguous
Caused by: com.mysql.jdbc.exceptions.MySQLIntegrityConstraintViolationException: Column 'ITEMID' in field list is ambiguous
Caused by: com.ibatis.common.jdbc.exception.NestedSQLException:
--- The error occurred in com/ibatis/jpetstore/persistence/sqlmapdao/sql/Item.xml.
--- The error occurred while applying a parameter map.
--- Check the getItem-InlineParameterMap.
--- Check the statement (query failed).
--- Cause: com.mysql.jdbc.exceptions.MySQLIntegrityConstraintViolationException: Column 'ITEMID' in field list is ambiguous
Caused by: com.mysql.jdbc.exceptions.MySQLIntegrityConstraintViolationException: Column 'ITEMID' in field list is ambiguous
at com.ibatis.dao.client.template.SqlMapDaoTemplate.queryForObject(SqlMapDaoTemplate.java:164)
at com.ibatis.jpetstore.persistence.sqlmapdao.ItemSqlMapDao.getItem(ItemSqlMapDao.java:42)
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:597)
at com.ibatis.dao.engine.impl.DaoProxy.invoke(DaoProxy.java:72)
at $Proxy7.getItem(Unknown Source)
at com.ibatis.jpetstore.service.CatalogService.getItem(CatalogService.java:59)
at com.ibatis.jpetstore.presentation.CartBean.addItemToCart(CartBean.java:60)
... 28 more
Caused by: com.ibatis.common.jdbc.exception.NestedSQLException:
--- The error occurred in com/ibatis/jpetstore/persistence/sqlmapdao/sql/Item.xml.
--- The error occurred while applying a parameter map.
--- Check the getItem-InlineParameterMap.
--- Check the statement (query failed).
--- Cause: com.mysql.jdbc.exceptions.MySQLIntegrityConstraintViolationException: Column 'ITEMID' in field list is ambiguous
Caused by: com.mysql.jdbc.exceptions.MySQLIntegrityConstraintViolationException: Column 'ITEMID' in field list is ambiguous
at com.ibatis.sqlmap.engine.mapping.statement.GeneralStatement.executeQueryWithCallback(GeneralStatement.java:185)
at com.ibatis.sqlmap.engine.mapping.statement.GeneralStatement.executeQueryForObject(GeneralStatement.java:104)
at com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.queryForObject(SqlMapExecutorDelegate.java:561)
at com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.queryForObject(SqlMapExecutorDelegate.java:536)
at com.ibatis.sqlmap.engine.impl.SqlMapSessionImpl.queryForObject(SqlMapSessionImpl.java:93)
at com.ibatis.sqlmap.engine.impl.SqlMapClientImpl.queryForObject(SqlMapClientImpl.java:70)
at com.ibatis.dao.client.template.SqlMapDaoTemplate.queryForObject(SqlMapDaoTemplate.java:162)
... 37 more
Caused by: com.mysql.jdbc.exceptions.MySQLIntegrityConstraintViolationException: Column 'ITEMID' in field list is ambiguous
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:931)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2985)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1631)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1723)
at com.mysql.jdbc.Connection.execSQL(Connection.java:3256)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1313)
at com.mysql.jdbc.PreparedStatement.execute(PreparedStatement.java:874)
at com.ibatis.sqlmap.engine.execution.SqlExecutor.executeQuery(SqlExecutor.java:180)
at com.ibatis.sqlmap.engine.mapping.statement.GeneralStatement.sqlExecuteQuery(GeneralStatement.java:205)
at com.ibatis.sqlmap.engine.mapping.statement.GeneralStatement.executeQueryWithCallback(GeneralStatement.java:173)
... 43 more找到那里的代码: public Item getItem(String itemId) {
Integer i = (Integer) queryForObject("getInventoryQuantity", itemId);
Item item = (Item) queryForObject("getItem", itemId);
item.setQuantity(i.intValue());
return item;
}相应的sql:<select id="getInventoryQuantity" resultClass="int" parameterClass="string">
SELECT QTY AS value
FROM INVENTORY
WHERE ITEMID = #itemId#
</select>
这不可能有错吧,最简单的一种sql了,居然说itemid混淆了,真晕,官网只有基于ibatis2的例子。
另外,有没有关于ibatis比较好的论坛?问题都没处问去。
那么你用的queryForObject ,应该要改成queryForList
不会吧,用hsqldb一点问题没有,数据都一样,ambiguous的意思就是说列名歧义了,因为参数名和列名一样了。
Column 'ITEMID' in field list is ambiguous
这个列明有问题,歧义了。
帖中贴的部分不对,应该是下面这个:
<select id="getItem" resultClass="item" parameterClass="string" cacheModel="quantityCache">
select
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>估计当时开发者用的mysql版本不是5.不同版本可能会有差异吧。