首先引用以下连接,从中得到答案:
http://www.newbooks.com.cn/info/118573.html
在我自己的实际项目中发生如下问题:
java 代码
- try {
- grpCustomerInfo.setCorporationname(corporationName);
- grpCustomerInfo.setProvince(province);
- grpCustomerInfo.setCity(city);
- grpCustomerInfo.setParentsign(ynoHO);
- grpCustomerInfo.setOrganizationproperty(organizationProperty);
- grpCustomerInfo.setParentcustomerid(mainCustomerIDForSub);
- grpCustomerInfo.setCorporationadds(corporationAdds);
- grpCustomerInfo.setCorporationproperty(corporationProperty);
- grpCustomerInfo.setTradetype(tradeType);
- grpCustomerInfo.setCorporationphone(corporationPhone);
- grpCustomerInfo.setCorporationfax(corporationFax);
- grpCustomerInfo.setPostalcode(postalcode);
- grpCustomerInfo.setFoundationdate(foundationDate);
- grpCustomerInfo.setSumpersons(Integer.getInteger(sumPersons));
- grpCustomerInfo.setCustomerid(maincustomerid);
- //管理机构
- grpCustomerInfo.setOrganization(organization);
- //操作者
- grpCustomerInfo.setOperator(operator);
- //操作时间
- grpCustomerInfo.setOperationTime(operationTime);
- grpCustomerInfo.getNewpolicies().add(this.getNewPolicy(printNO));
- this.getNewPolicy(printNO).setGrpcustomerinfo(grpCustomerInfo);
- this.getGrpCustomerInfoDAO().save(grpCustomerInfo);
- this.getNewPolicyDAO().update(this.getNewPolicy(printNO));
- //设置表Savenewpolicystate的Savecustomerinofstate字段为1,该字段表示客户信息已经保存
- //客户信息录入状态
- this.getNewPolicy(printNO).getSavenewpolicystate().setSavecustomerinofstate("1");
- this.getSaveNewPolicyStateDAO().update(this.getNewPolicy(printNO).getSavenewpolicystate());
- bl=true;
- } catch (Exception e) {
- e.printStackTrace();
- }
- return bl;
但是如果将24行到29行顺序调整为:
java 代码
- this.getNewPolicy(printNO).setGrpcustomerinfo(grpCustomerInfo);
- //设置表Savenewpolicystate的Savecustomerinofstate字段为1,该字段表示客户信息已经保存
- //客户信息录入状态
- this.getNewPolicy(printNO).getSavenewpolicystate().setSavecustomerinofstate("1");
- this.getGrpCustomerInfoDAO().save(grpCustomerInfo);
- this.getNewPolicyDAO().update(this.getNewPolicy(printNO));
- this.getSaveNewPolicyStateDAO().update(this.getNewPolicy(printNO).getSavenewpolicystate());
将会发生Object references an unsaved transient instance的问题.
因为"某个对象的某个属性是一个实体,在这个实体没有保存之前就保存这个对象而造成了这个错误。"在以上例子中this.getNewPolicy(printNO)没有保存,就在以下的程序中使用了,this.getNewPolicy(printNO).getSavenewpolicystate().所以出现错误!