最近在做项目时出现的错误。如下:
org.hibernate.TransientObjectException: object references an unsaved transient instance - save the transient instance before flushing:
这个错误可能是由以下原因引起的:
1、save顺序不正确
比如公司表和职员表,职员表存有公司的ID外键,是一对多的关系。在进行操作的时候应该是先执行公司表的save操作,再执行职员表的save操作。
2、在执行一对多的添加操作时,未对新增的对象的实行save操作。