首先引用以下连接,从中得到答案:
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));
-
-
- 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);
-
-
-
- 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().所以出现错误!
分享到:
相关推荐
3.Caused by:org.hibernate.TransientObjectException:object references an unsaved transient instance 原因:代码中关联的对象没有set值进去。查看代码,发现是enterPriseStrength和enterprise为多对一
在调试过程中,可能会遇到`Caused by: org.hibernate.TransientObjectException: object references an unsaved transient instance`这样的异常。这个异常通常是因为在持久化操作时,关联的对象没有被正确设置。例如...
org.hibernate.TransientObjectException: object references an unsaved transient instance 当一个实体引用了另一个尚未保存的实体时,会抛出此类异常。这通常发生在级联保存的场景中,如果父实体尝试保存时,子...
TransientObjectException: object references an unsaved transient instance 这个异常通常发生在级联操作中,例如当配置了`cascade="save-update,persist"`。如果在保存一个对象时,该对象引用了一个未保存的...
**TransientObjectException: object references an unsaved transient instance** **异常描述:** 此异常表示一个实体引用了另一个尚未保存的瞬态实体。 **解决方法:** - 在保存实体之前先保存所有关联的瞬态...
`org.hibernate.TransientObjectException`: object references an unsaved transient instance** - **异常描述**:当尝试保存一个对象时,该对象引用了一个尚未被持久化的对象。 - **原因分析**:通常发生在尝试...