小强大扫荡

       BUG的总结
 
 

 

 

1, hbm主键生成策略错误:

 

Struts Problem Report

Struts has detected an unhandled exception:

Messages:

    ids for this class must be manually assigned before calling save(): cn.itcast.bos.domain.bc.Standard ids for this class must be manually assigned before calling save(): cn.itcast.bos.domain.bc.Standard; nested exception is org.hibernate.id.IdentifierGenerationException: ids for this class must be manually assigned before calling save(): cn.itcast.bos.domain.bc.Standard

File:

org/hibernate/id/Assigned.java

Line number:

53

Stacktraces

org.springframework.orm.hibernate3.HibernateSystemException:ids for this class must be manually assigned before calling save():cn.itcast.bos.domain.bc.Standard; nested exception isorg.hibernate.id.IdentifierGenerationException: ids for this class must bemanually assigned before calling save(): cn.itcast.bos.domain.bc.Standard

 

解决:

反向生成的PO和hbm,在hbm中的主键生成策略是assigned。如果主键是String类型的,则需要将这个修改成uuid,就可以修正错误。

 

 

2,延迟加载出错,报没有session。

Struts Problem Report

Struts has detected an unhandled exception:

Messages:

    could not initialize proxy - no Session java.lang.reflect.InvocationTargetException org.apache.struts2.json.JSONException: java.lang.reflect.InvocationTargetException org.apache.struts2.json.JSONException: org.apache.struts2.json.JSONException: java.lang.reflect.InvocationTargetException

File:

org/hibernate/proxy/AbstractLazyInitializer.java

Line number:

167

Stacktraces

org.apache.struts2.json.JSONException:

org.apache.struts2.json.JSONException:

org.apache.struts2.json.JSONException:java.lang.reflect.InvocationTargetException

 

注意表格中的红色加粗字,初次看到这个信息的时候,可以猜到是懒加载造成的session关闭,

解决方法:通过在web.xml中配置过滤器解决,

 

 

OpenSessionInViewFilter org.springframework.orm.hibernate3.support.OpenSessionInViewFilter

 

 

OpenSessionInViewFilter

 

 

 

 

3,由数据表外键引发的异常:

Struts Problem Report

Struts has detected an unhandled exception:

Messages:

    Cannot add or update a child row: a foreign key constraint fails (`mvbos`.`bc_subarea`, CONSTRAINT `FK_area_region` FOREIGN KEY (`region_id`) REFERENCES `bc_region` (`id`)) Could not execute JDBC batch update Could not execute JDBC batch update; SQL [update mvbos.bc_subarea set decidedzone_id=?, region_id=?, addresskey=?, startnum=?, endnum=?, single=?, position=? where id=?]; constraint [null]; nested exception is org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update

File:

com/mysql/jdbc/PreparedStatement.java

Line number:

1,666

Cannot add or update a child row: a foreign keyconstraint fails (`mvbos`.`bc_subarea`, CONSTRAINT `FK_area_region` FOREIGN KEY(`region_id`) REFERENCES `bc_region` (`id`))

这句话的意思是:bc_subarea表的外键指向了bc_region的id属性。也就是说,subarea的存在依赖于region,没有region就没有subarea,所以必须要先存在region。才可以。

得出出现错误的原因:

在保存subarea的时候,subarea中指向region的外键的值,在region表中不存在。

解决方式:

查看是否是subarea的外键输入错误,或者建立id等于subarea的外键的region数据记录。

 

4,struts.xml中不配result

 


 

Noresult defined for action cn.itcast.bos.web.action.subarea.SubareaAction andresult upload

出现原因:在Action中定义了返回结果upload,但是在struts.xml中没有配置接收upload的result。

解决方案:在struts.xml中配置result。

5,不能实例化action。

Struts Problem Report

Struts has detected an unhandled exception:

Messages:

    regionAction Unable to instantiate Action, regionAction, defined for 'regionAction_pageQuery' in namespace '/'regionAction

File:

org/apache/catalina/loader/WebappClassLoader.java

Line number:

1,645


Stacktraces

Unable to instantiate Action,regionAction, defined for 'regionAction_pageQuery' in namespace '/'regionAction

原因:spring管理action时,需要在applicationContext.xml中配置action的实现类,出现这个问题是因为在spring的核心配置文件中,这个action的实现类的id与struts.xml中的class值不一致了。

解决:查看struts.xml的这个action的class属性和applicationContext.xml的这个action的id属性是否一致,如果不一致,修改其一,使其一致即可。

 

 

 

7,主键生成策略设置不当产生的异常

Struts Problem Report

Struts has detected an unhandled exception:

Messages:

    Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1 Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1; nested exception is org.hibernate.StaleStateException: Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1

File:

org/hibernate/jdbc/Expectations.java

Line number:

85


Stacktraces

org.springframework.orm.hibernate3.HibernateOptimisticLockingFailureException:Batch update returned unexpected row count from update [0]; actual row count:0; expected: 1; nested exception is org.hibernate.StaleStateException: Batchupdate returned unexpected row count from update [0]; actual row count: 0;expected: 1

 

解决:查看hbm文件中的主键生成策略。

8,tomcat启动时报session错误

严重: IOExceptionwhile loading persisted sessions: java.io.EOFException

严重: Exception loading sessions from persistent storage

解决:

说法一:根本原因是给tomcat设置的缓存太小,解决的办法就是在eclipse的tomcat里配置一下所使用的内存大小

说法二:分析:EOFException表示输入过程中意外地到达文件尾或流尾的信号,导致从session中获取数据失败。异常是tomcat本身的问题,由于tomcat上次非正常关闭时有一些活动session被持久化(表现为一些临时文件),在重启时,tomcat尝试去恢复这些session的持久化数据但又读取失败造成的。此异常不影响系统的使用。

解决办法:将tomcat6.0\work\Catalina\localhost\peam\SESSIONS.ser删除。如果正常关闭服务端,该文件是自动删除的。

我参照上面方法解决的问题,用的是MyEclipse6.0,tomcat6.0。通常情况下,会认为是tomcat的缓存,会直接把整个localhost文件夹删除。但是上面的方法也是可取的,在localhost文件夹下,找到部署的工程名,在该工程名下有SESSIONS.ser文件,直接删除。重启tomcat,问题解决。

 

9,WebService发布报错

Exception in thread "main" com.sun.xml.internal.ws.model.RuntimeModelerException: runtime modeler error: Wrapper class cn.itcast.ws.jaxws.SayHello is notfound. Have you run APT to generate them?

原因:很可能是JDK的版本不够造成的,建议JDK1.6u17之后的版本,最好改成1.7。

解决:升级JDK到1.7即可。

 

 
posted @ 2016-06-03 18:33  三个臭皮匠  阅读(173)  评论(0编辑  收藏  举报