ITeye博客

运用struts2、hibernate、spring中的常见错误

Chevy · 2009-04-02 16:44 · 整理笔记 · Markdown

学习应用了struts和hibernate、spring进行javaweb开发已经一个多月了,在做招聘信息的小项目中出现过很多报错,现在把这些报错当作笔记记载下来,其中一些的后台报错没有记录下来,只好用语言描述一下。下面就是我整理的错误: 1. 笔记:在用hibernate时,用现成的表的时候,表中的字段必须都包括,否则会报错(这个问题在后期的spring集成中没有出现,对数据库中表操作 为update一定没事。注:整个项目是应用maven生成的,所以在pom.xml文件中对数据库的修改由create-drop为update,同时项目是基于svn下载 的脚本架编写的)

2. filter过滤器中的是sessin的打开,action,.jsp;(主要针对于过滤jsp的session打开)

3. 如果在struts2和hibernate中报没有实体错误时,可以写 if(entity != null){执行程序段;}(没有什么不理解的)

4. FreeMarker template error!这个问题很诡异,一般由空值引起,准确的说是对象传递过程中出现错误.(这个问题当时困扰了我一天!)

5. id 报错(在后面会提到)

6. 增加hidden name="entity.id"时产生错误,不能向数据库插入了,原因在于id不能为空,在entity类里,setId里面这样写 if (id != null && !id.isEmpty()) { this.id = id; } (这里的id是String型.) 7. org.hibernate.exception.GenericJDBCException: Could not execute JDBC batch update 这个异常就当时做的,发现是由于数据库字段类型与hibernate中,bean类对象的属性类型不匹配

8. HTTP ERROR: 404 NOT_FOUND

RequestURI=/mywork/citySave

解答:不允许jsp直接提交form表单到action要通过struts2初始化,即forward(action)到jsp

9. Nested in org.apache.jasper.JasperException: tag 'select', field 'list', name 'job.city.id': The requested list key 'cities' cou ld not be resolved as a collection/array/map/enumeration/iterator type. Example: people or people.{name} - : tag 'select', field 'list', name 'job.city.id': The requested list key 'cities' could not be resolved as a collection/array/map/enumeration/iterator type. Examp le: people or people.{name} -

解答:与spring集成时要核对准:jobDao,cityDao;两者不能少(spring配置文件中bean属性)

10. could not initialize proxy - no Session

解答:延迟加载问题:要设为false就没问题了

11. 请注意:class="job.Job"中的包.类

12. photoDao在配置文件里找不到 错误:在Bean没有写上parent="dao"即sessionFactory

13. 问题:在上传图片或文件时,出现这种错误:Invalid field value for field "photoFile";并且在后台没有报错,没有异常显示 原因:在标签中<s:form action="photoUpload" method="post" >少了这个enctype="multipart/form-data"

14. java.lang.IllegalArgumentException: id to load is required for loading 错误为:要查询的参数与传入的参数不一致,或是因为参数为null

15. 问题:Batch update returned unexpected row count from update ; actual row count: 0; expected: 1; nested exception is org.hibernate.StaleStateException: Batch update returned unexpected row count from update ; actual row count: 0; expected:1 解决:public void setId(String id) { if(id != null && !id.isEmpty()){ this.id = id; } }

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。