com.dc.base.exception.SystemException异常处理

tech2026-08-22  1

代码编译运行时都没报错,走保存方法的时候,hibernate提交事务时,报了以下的错:

com.dc.base.exception.SystemException: object references an unsaved transient instance - save the transient instance before flushing: com.gaotai.zhxy.oa.entity.OaMeeting; nested exception is org.hibernate.TransientObjectException: object references an unsaved transient instance - save the transient instance before flushing: com.gaotai.zhxy.oa.entity.OaMeeting at com.dc.base.web.springmvc.RestfulResponseErrorHandler.handleError

网上搜了一下,说是在调用hibernate存储数据时,需要将数据库中表对应的持久类对象作为参数传递。如果用得到对象中的数据,那么调用持久层的方法重新查询出对应的对象,此对象此时为持久态,在重新赋值到要保存的对象中即可。

简单通俗的来说,当两张表存在映射关系时,关联表需要主表的外键作为关联存储数据,如果关联的主表的外键(一般都为id)为null时,所关联的表无法取得对应的键值,则无法存储对应的数据。

解决方法

查看方法是否是先保存主表,如果是先保存主表,可以跟断点看一下主表的与关联表的外键是否存在,如果存在,则往下继续看关联表是否取到对应的值

最新回复(0)