JPetStore 源代码部署的问题

最近在用iBATIS ,下载了 http://apache.freelamp.com//ibatis/binaries/ibatis.java/JPetStore-5.0.zip 学习。用源代码部署,我用的是MySql数据库。测试发现有如下bug:

Error!
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

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.java249)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java419)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java224)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java1194)
at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java414)
at javax.servlet.http.HttpServlet.service(HttpServlet.java617)
at javax.servlet.http.HttpServlet.service(HttpServlet.java717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java191)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java470)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java298)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java857)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java588)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java489)
at java.lang.Thread.run(Thread.java619)
Caused by org.apache.struts.beanaction.BeanActionException Error invoking Action.  Cause java.lang.reflect.InvocationTargetException
at org.apache.struts.beanaction.ActionInvoker.invoke(ActionInvoker.java18)
at org.apache.struts.beanaction.DefaultActionInterceptor.intercept(DefaultActionInterceptor.java5)
at org.apache.struts.beanaction.BeanAction.execute(BeanAction.java246)
... 19 more
Caused by java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java25)
at java.lang.reflect.Method.invoke(Method.java597)
at org.apache.struts.beanaction.ActionInvoker.invoke(ActionInvoker.java16)
... 21 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 comibatisjpetstorepersistencesqlmapdaosqlItem.xml. 
--- The error occurred while applying a parameter map. 
--- Check the getItem-InlineParameterMap. 
--- Check the statement (query failed). 
--- Cause com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException Column 'ITEMID' in field list is ambiguous
Caused by com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException Column 'ITEMID' in field list is ambiguous
Caused by com.ibatis.common.jdbc.exception.NestedSQLException  
--- The error occurred in comibatisjpetstorepersistencesqlmapdaosqlItem.xml. 
--- The error occurred while applying a parameter map. 
--- Check the getItem-InlineParameterMap. 
--- Check the statement (query failed). 
--- Cause com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException Column 'ITEMID' in field list is ambiguous
Caused by com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException Column 'ITEMID' in field list is ambiguous
at com.ibatis.dao.client.template.SqlMapDaoTemplate.queryForObject(SqlMapDaoTemplate.java164)
at com.ibatis.jpetstore.persistence.sqlmapdao.ItemSqlMapDao.getItem(ItemSqlMapDao.java42)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java25)
at java.lang.reflect.Method.invoke(Method.java597)
at com.ibatis.dao.engine.impl.DaoProxy.invoke(DaoProxy.java72)
at $Proxy0.getItem(Unknown Source)
at com.ibatis.jpetstore.service.CatalogService.getItem(CatalogService.java59)
at com.ibatis.jpetstore.presentation.CartBean.addItemToCart(CartBean.java60)
... 26 more
Caused by com.ibatis.common.jdbc.exception.NestedSQLException  
--- The error occurred in comibatisjpetstorepersistencesqlmapdaosqlItem.xml. 
--- The error occurred while applying a parameter map. 
--- Check the getItem-InlineParameterMap. 
--- Check the statement (query failed). 
--- Cause com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException Column 'ITEMID' in field list is ambiguous
Caused by com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException Column 'ITEMID' in field list is ambiguous
at com.ibatis.sqlmap.engine.mapping.statement.GeneralStatement.executeQueryWithCallback(GeneralStatement.java185)
at com.ibatis.sqlmap.engine.mapping.statement.GeneralStatement.executeQueryForObject(GeneralStatement.java104)
at com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.queryForObject(SqlMapExecutorDelegate.java561)
at com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.queryForObject(SqlMapExecutorDelegate.java536)
at com.ibatis.sqlmap.engine.impl.SqlMapSessionImpl.queryForObject(SqlMapSessionImpl.java93)
at com.ibatis.sqlmap.engine.impl.SqlMapClientImpl.queryForObject(SqlMapClientImpl.java70)
at com.ibatis.dao.client.template.SqlMapDaoTemplate.queryForObject(SqlMapDaoTemplate.java162)
... 35 more
Caused by com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException Column 'ITEMID' in field list is ambiguous
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java27)
at java.lang.reflect.Constructor.newInstance(Constructor.java513)
at com.mysql.jdbc.Util.handleNewInstance(Util.java409)
at com.mysql.jdbc.Util.getInstance(Util.java384)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java1041)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java3566)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java3498)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java1959)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java2113)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java2568)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java2113)
at com.mysql.jdbc.PreparedStatement.execute(PreparedStatement.java1364)
at com.ibatis.sqlmap.engine.execution.SqlExecutor.executeQuery(SqlExecutor.java180)
at com.ibatis.sqlmap.engine.mapping.statement.GeneralStatement.sqlExecuteQuery(GeneralStatement.java205)
at com.ibatis.sqlmap.engine.mapping.statement.GeneralStatement.executeQueryWithCallback(GeneralStatement.java173)
... 41 more

主要是 src\com\ibatis\jpetstore\persistence\sqlmapdao\sql\Item.xml 数据查询有问题。
   修改一处查询语句就可以了:
  <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>

你可能感兴趣的:(apache,mysql,ibatis,struts,jdbc)