Java项目开发中一些BUG的总结

1,JVM Bind


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

Struts Problem Report

Struts has detected an unhandled exception:

Messages:

  1. ids for this class must be manually assigned before calling save(): cn.itcast.bos.domain.bc.Standard
  2. 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,就可以修正错误。

 

 

3,延迟加载出错,报没有session

Struts Problem Report

Struts has detected an unhandled exception:

Messages:

  1. could not initialize proxy - no Session
  2. java.lang.reflect.InvocationTargetException
  3. org.apache.struts2.json.JSONException: java.lang.reflect.InvocationTargetException
  4. 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中配置过滤器解决,

<!-- 解决延迟加载异常 -->

<filter>

   <filter-name>OpenSessionInViewFilter</filter-name> <filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>

 </filter>

 <filter-mapping>

   <filter-name>OpenSessionInViewFilter</filter-name>

   <url-pattern>/*</url-pattern>

  </filter-mapping>

 

 

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

Struts Problem Report

Struts has detected an unhandled exception:

Messages:

  1. 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`))
  2. Could not execute JDBC batch update
  3. 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数据记录。

 

5,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。

6,不能实例化action

Struts Problem Report

Struts has detected an unhandled exception:

Messages:

  1. regionAction
  2. 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:

  1. Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1
  2. 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即可。


  • 5
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值