最近在用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>
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>
相关推荐
通过详细研究jpetstore源代码,开发者不仅可以掌握J2EE的基础知识,还能深入了解如何在实际项目中应用设计模式,提升软件开发的效率和质量。同时,这个项目也适合作为面试准备,因为它覆盖了J2EE开发中的许多核心...
在部署方面,jpetstore会依赖于Web服务器如Apache Tomcat或Jetty,这些服务器能够运行Servlet和JSP。同时,它也需要Java运行环境(JRE)和Java Development Kit(JDK)来编译和运行。 总的来说,jpetstore是一个...
`java`目录下存放着项目的Java源代码,包括业务逻辑、模型对象、DAO(数据访问对象)和控制器等。`resources`可能包含配置文件,如iBATIS的XML映射文件、Spring配置文件等。 4. **web**:这是Web应用的部分,可能...
**文件名列表:“jpetstore”** 这个文件名可能是JPetStore项目的源代码压缩包,包含了所有必要的类、配置文件和其他资源,用于构建和运行这个集成Struts、Spring和Hibernate的电子商务应用。开发者可以解压后,在...
这些工具自动下载所需的库,编译源代码,生成WAR文件,以便在Web服务器上部署。 **8. Tomcat或Jetty等应用服务器** 最后,开发完成后,JPetStore需要部署到应用服务器上,如Apache Tomcat或Jetty。这些服务器运行...
- **src/main/java**:包含了所有的Java源代码,包括实体类、DAO接口和实现、服务层类等。 - **src/main/resources**:存储了配置文件,如iBATIS的SqlMapConfig.xml,以及可能的数据库脚本。 - **src/main/webapp**...
### SQL + JPetStore配置详解 #### 一、概述 JPetStore是一个广泛使用的开源示例应用程序,...通过以上步骤,您可以成功地在本地环境中部署并运行JPetStore 5.0,并且能够有效地解决配置过程中可能遇到的各种问题。
`jpetstore`通常会有一个清晰的目录结构,包含`src/main/java`(业务逻辑代码)、`src/main/resources`(配置文件)、`src/main/webapp`(Web应用资源)等。`src/main/webapp`下会有`WEB-INF`目录,其中包含`web....
3. **src**:源代码目录,一般包括项目的Java源文件、配置文件等。在这个项目中,你可以找到控制器、模型、视图以及与Ibatis相关的映射文件。Ibatis的Mapper接口和XML配置文件通常会放在这里,以便实现业务逻辑与...
通过研究它的源代码,开发者可以深入理解Struts框架的工作原理,掌握MVC模式的应用,以及如何组织一个典型的Java Web项目。此外,它也展示了如何与数据库交互、如何处理用户请求、如何设计和使用JavaBeans,以及如何...
文件名称"hjpetstore"可能代表这个项目的主要源代码或编译后的部署单元。通常,一个SSH项目会包含以下组成部分: 1. **配置文件**:如struts.xml(Struts2配置)、spring-context.xml(Spring配置)、hibernate.cfg....
1. **源代码**: 包含Action类、Service层、DAO层以及相关的业务逻辑。 2. **配置文件**: 如struts.xml,定义Action映射和拦截器栈。 3. **视图资源**: JSP或Freemarker模板,用于渲染用户界面。 4. **资源文件**: ...
在【压缩包子文件的文件名称列表】"org.springframework.samples.jpetstore"中,我们可以推测这个压缩包包含的是jpetstore项目的源代码,位于"org.springframework.samples"包下,这是一个标准的Java项目结构,表明...
文件列表中的`JPetStore-5.0`可能是JpetStore的源代码。通过“File” -> “Import” -> “Existing Projects into Workspace”,选择项目的根目录,确保“Copy projects into workspace”选项被选中,然后点击...
将JPetStore工程导入到MyEclipse中,可以利用其内置的工具进行代码编写、调试和部署,大大提高了开发效率。在导入过程中,需确保MyEclipse已经安装了Spring相关的插件,如Spring Tools Suite(STS),以支持Spring...
此外,`JPetStore`还涉及了其他的Java EE技术,如JNDI(Java Naming and Directory Interface)用于查找数据源,JTA(Java Transaction API)处理事务管理,以及Servlet容器(如Tomcat)来部署和运行应用程序。...
它遵循MVC设计模式,将业务逻辑、表示层和控制逻辑分离,使得代码结构清晰,易于维护。Struts通过ActionForm、控制器Servlet(ActionServlet)以及一系列配置文件(struts-config.xml)来协调各个组件的工作。 **2....
2. **导入源代码**:将解压后的Spring JPetStore 2.5源代码复制到项目目录下,并在MyEclipse中导入这些源文件。 3. **配置构建路径**:确保所有的类库(如Spring、Hibernate、Struts等)被添加到项目的构建路径中,...
1. `src/main/java`:存放Java源代码,包括业务逻辑、DAO层、服务接口和服务实现等。 2. `src/main/resources`:存放配置文件,如Spring的bean定义XML文件,数据库连接配置等。 3. `src/main/webapp`:Web应用目录,...
在Java Web开发中,JSP是一种用于创建动态网页的技术,它允许开发者在HTML代码中嵌入Java代码,从而实现服务器端的数据处理和业务逻辑。JSP文件会被Web容器(如Tomcat)转换为Servlet,然后执行并生成HTML响应返回给...