系统:Spring MVC+Hibernate
最后跟踪找到原因:
引用对象(many-to-one)不存在,Hibernate在保存对象时如果有many-to-one,必须存在。否则需手动设置为null.
跟踪:报错处打印处理的对象存在,需跟踪前一个对象。Hibernate在save新对象时先保存前一个Save对象,碰到下一个Save时才保存此对象:
错误日志:
org.hibernate.TransientObjectException: object references an unsaved transient instance - save the transient instance before flushing: com.xx.xx.xx.xx.Xxx 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:225) at org.hibernate.type.ManyToOneType.isDirty(ManyToOneType.java:235) 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:329) at com.hestia.mosa.qcy.dao.QcyUnitedOrderInfoDAOImpl.getObject(QcyUnitedOrderInfoDAOImpl.java:211) at com.hestia.mosa.qcy.service.QcyUnitedOrderInfoServiceImpl.importOuter(QcyUnitedOrderInfoServiceImpl.java:480) 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:309) 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 $Proxy88.importOuter(Unknown Source) 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:309) 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 $Proxy89.importOuter(Unknown Source) at com.hestia.mosa.qcy.controller.QcyUnitedOrderInfoController.importOuter(QcyUnitedOrderInfoController.java:939) 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:151) 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:859) 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)
相关推荐
在Java世界中,Java Persistence API(JPA)是Oracle公司推出的用于对象关系映射(ORM)的标准框架,它简化了数据库操作,使开发者能够用Java对象来操作数据库记录。本教程将深入探讨JPA中的一对多双向关联及级联...
3.Caused by:org.hibernate.TransientObjectException:object references an unsaved transient instance 原因:代码中关联的对象没有set值进去。查看代码,发现是enterPriseStrength和enterprise为多对一
TransientObjectException: object references an unsaved transient instance 这个异常通常发生在级联操作中,例如当配置了`cascade="save-update,persist"`。如果在保存一个对象时,该对象引用了一个未保存的...
org.hibernate.TransientObjectException: object references an unsaved transient instance 当一个实体引用了另一个尚未保存的实体时,会抛出此类异常。这通常发生在级联保存的场景中,如果父实体尝试保存时,子...
在调试过程中,可能会遇到`Caused by: org.hibernate.TransientObjectException: object references an unsaved transient instance`这样的异常。这个异常通常是因为在持久化操作时,关联的对象没有被正确设置。例如...
`org.hibernate.TransientObjectException`: object references an unsaved transient instance** - **异常描述**:当尝试保存一个对象时,该对象引用了一个尚未被持久化的对象。 - **原因分析**:通常发生在尝试...
* org.hibernate.TransientObjectException: 对象引用了未保存的瞬态实例 + 解决方案:检查对象是否已经被保存,如果没有,则需要调用 save() 或 update() 方法来保存对象。 * org.springframework.orm.hibernate3....
**TransientObjectException: object references an unsaved transient instance** **异常描述:** 此异常表示一个实体引用了另一个尚未保存的瞬态实体。 **解决方法:** - 在保存实体之前先保存所有关联的瞬态...
- **Transient(瞬态)**:对象未与Hibernate Session关联,未被持久化,其生命周期完全由应用程序控制。 - **Persistent(持久化)**:对象存在于Session中,与数据库中的记录对应,一旦改变,其变化会同步到...