程序执行到这个方法中for循环第一次时不报错,执行第二次到 BdMaterial product = (BdMaterial) this.getPurcInquiryInfoDAO().getObject("from BdMaterial as t where t.no = '"+ template.getItemNo() + "'");报错!!不知道怎么解决啦啊!!!希望那位师父指教一下,感谢啦!
@Override
public void importOuter(PurcInquiryInfo pageObject) throws Exception {
// TODO Auto-generated method stub
if (null == pageObject.getId())
this.getPurcInquiryInfoDAO().save(pageObject);
else
this.getPurcInquiryInfoDAO().update(pageObject);
// 删除原有的表身
if (null != pageObject.getId()) {
String hql = "delete from PurcInquiryInfoItem where header.id="
+ pageObject.getId() + ")";
this.getPurcInquiryInfoDAO().executeUpdate(hql);
}
if (null != pageObject.getId()
&& null != pageObject.getTemplate().getId()) {
List<PurcInquiryTemplateItem> templateItem = new ArrayList<PurcInquiryTemplateItem>();
templateItem = (List<PurcInquiryTemplateItem>) this
.getPurcInquiryInfoDAO().executeQuery(
"from PurcInquiryTemplateItem as m where m.template.id="
+ pageObject.getTemplate().getId());
for (int i = 0; i < templateItem.size(); i++) {
PurcInquiryTemplateItem template = new PurcInquiryTemplateItem();
PurcInquiryInfoItem item = new PurcInquiryInfoItem();
template = templateItem.get(i);
BdMaterial product = (BdMaterial) this.getPurcInquiryInfoDAO().getObject("from BdMaterial as t where t.no = '"+ template.getItemNo() + "'");
item.setHeader(pageObject);
item.setItemNo(template.getItemNo());
item.setItemName(template.getItemName());
if (null != product) {
item.setBasicUnit(product.getDefaultUnit());
}
this.getPurcInquiryInfoDAO().saveObject(item);
} }
}
[2012-11-21.17:57:41]ERROR - [com.hestia.mosa.purchase.controller.PurcInquiryInfoController:line 597]object references an unsaved transient instance - save the transient instance before flushing: com.hestia.mosa.basedata.vo.UnitFactor
org.hibernate.TransientObjectException: object references an unsaved transient instance - save the transient instance before flushing: com.hestia.mosa.basedata.vo.UnitFactor
at org.hibernate.engine.ForeignKeys.getEntityIdentifierIfNotUnsaved(ForeignKeys.java:219)
at org.hibernate.type.EntityType.getIdentifier(EntityType.java:407)
at org.hibernate.type.ManyToOneType.isDirty(ManyToOneType.java:242)
at org.hibernate.type.TypeFactory.findDirty(TypeFactory.java:597)
at org.hibernate.persister.entity.AbstractEntityPersister.findDirty(AbstractEntityPersister.java:3118)
at org.hibernate.event.def.DefaultFlushEntityEventListener.dirtyCheck(DefaultFlushEntityEventListener.java:479)
at org.hibernate.event.def.DefaultFlushEntityEventListener.isUpdateNecessary(DefaultFlushEntityEventListener.java:204)
at org.hibernate.event.def.DefaultFlushEntityEventListener.onFlushEntity(DefaultFlushEntityEventListener.java:127)
at org.hibernate.event.def.AbstractFlushingEventListener.flushEntities(AbstractFlushingEventListener.java:196)
at org.hibernate.event.def.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:76)
at org.hibernate.event.def.DefaultAutoFlushEventListener.onAutoFlush(DefaultAutoFlushEventListener.java:35)
at org.hibernate.impl.SessionImpl.autoFlushIfRequired(SessionImpl.java:970)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1115)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
at org.hibernate.impl.AbstractQueryImpl.uniqueResult(AbstractQueryImpl.java:811)
at common.baseclass.CommonDAO.get(CommonDAO.java:214)
at com.hestia.mosa.purchase.dao.PurcInquiryInfoDAOImpl.getObject(PurcInquiryInfoDAOImpl.java:41)
at com.hestia.mosa.purchase.service.PurcInquiryInfoServiceImpl.importOuter(PurcInquiryInfoServiceImpl.java:134)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:307)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:108)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
at $Proxy47.importOuter(Unknown Source)
at com.hestia.mosa.purchase.controller.PurcInquiryInfoController.importOuter(PurcInquiryInfoController.java:593)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.springframework.web.servlet.mvc.multiaction.MultiActionController.invokeNamedMethod(MultiActionController.java:471)
at org.springframework.web.servlet.mvc.multiaction.MultiActionController.handleRequestInternal(MultiActionController.java:408)
at org.springframework.web.servlet.mvc.AbstractController.handleRequest(AbstractController.java:153)
at org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:48)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:771)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:716)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:647)
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:563)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:198)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at common.filter.SetCharacterEncodingFilter.doFilter(SetCharacterEncodingFilter.java:141)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:852)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Unknown Source)
在实体类中UnitFactor类 作为PurcInquiryInfo的属性声明的
声明方式为 private UnitFactor uf = new UnitFactor();
这种方法在执行上面的代码就是报错,说引用对象为保存。
后来将声明方式修改为private UnitFactor uf; 这种方式执行上述代码就没有问题
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。