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

2014-11-24 08:04:58 · 作者: · 浏览: 0

1,JVM Bind

\

2, 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,就可以修正错误。

3,延迟加载出错,报没有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

/*

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

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数据记录。

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: