关于Object references an unsaved transient instance

阅读更多

首先引用以下连接,从中得到答案:

http://www.newbooks.com.cn/info/118573.html

在我自己的实际项目中发生如下问题:

java 代码
  1. try {   
  2.             grpCustomerInfo.setCorporationname(corporationName);   
  3.             grpCustomerInfo.setProvince(province);   
  4.             grpCustomerInfo.setCity(city);   
  5.             grpCustomerInfo.setParentsign(ynoHO);   
  6.             grpCustomerInfo.setOrganizationproperty(organizationProperty);   
  7.             grpCustomerInfo.setParentcustomerid(mainCustomerIDForSub);   
  8.             grpCustomerInfo.setCorporationadds(corporationAdds);   
  9.             grpCustomerInfo.setCorporationproperty(corporationProperty);   
  10.             grpCustomerInfo.setTradetype(tradeType);   
  11.             grpCustomerInfo.setCorporationphone(corporationPhone);   
  12.             grpCustomerInfo.setCorporationfax(corporationFax);   
  13.             grpCustomerInfo.setPostalcode(postalcode);   
  14.             grpCustomerInfo.setFoundationdate(foundationDate);   
  15.             grpCustomerInfo.setSumpersons(Integer.getInteger(sumPersons));             
  16.             grpCustomerInfo.setCustomerid(maincustomerid);   
  17.             //管理机构   
  18.             grpCustomerInfo.setOrganization(organization);   
  19.             //操作者   
  20.             grpCustomerInfo.setOperator(operator);   
  21.             //操作时间   
  22.             grpCustomerInfo.setOperationTime(operationTime);   
  23.             grpCustomerInfo.getNewpolicies().add(this.getNewPolicy(printNO));   
  24.             this.getNewPolicy(printNO).setGrpcustomerinfo(grpCustomerInfo);   
  25.             this.getGrpCustomerInfoDAO().save(grpCustomerInfo);   
  26.             this.getNewPolicyDAO().update(this.getNewPolicy(printNO));   
  27.             //设置表Savenewpolicystate的Savecustomerinofstate字段为1,该字段表示客户信息已经保存   
  28.             //客户信息录入状态   
  29.             this.getNewPolicy(printNO).getSavenewpolicystate().setSavecustomerinofstate("1");              
  30.                
  31.             this.getSaveNewPolicyStateDAO().update(this.getNewPolicy(printNO).getSavenewpolicystate());   
  32.             bl=true;   
  33.         } catch (Exception e) {   
  34.             e.printStackTrace();   
  35.         }   
  36.         return bl;  

 但是如果将24行到29行顺序调整为:

java 代码
  1. this.getNewPolicy(printNO).setGrpcustomerinfo(grpCustomerInfo);   
  2.   
  3. //设置表Savenewpolicystate的Savecustomerinofstate字段为1,该字段表示客户信息已经保存   
  4. //客户信息录入状态   
  5. this.getNewPolicy(printNO).getSavenewpolicystate().setSavecustomerinofstate("1");   
  6.   
  7. this.getGrpCustomerInfoDAO().save(grpCustomerInfo);   
  8. this.getNewPolicyDAO().update(this.getNewPolicy(printNO));   
  9. this.getSaveNewPolicyStateDAO().update(this.getNewPolicy(printNO).getSavenewpolicystate());  

将会发生Object references an unsaved transient instance的问题.

因为"某个对象的某个属性是一个实体,在这个实体没有保存之前就保存这个对象而造成了这个错误。"在以上例子中this.getNewPolicy(printNO)没有保存,就在以下的程序中使用了,this.getNewPolicy(printNO).getSavenewpolicystate().所以出现错误!

你可能感兴趣的:(项目管理,HTML)