2
回答
TransientObjectException 保存的对象被引用异常
利用AWS快速构建适用于生产的无服务器应用程序,免费试用12个月>>>   

程序执行到这个方法中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)


举报
pengcheng_1024
发帖于5年前 2回/478阅
顶部