Hibernate常见错误之save the transient instance before flushing
在Hibernate多表操作的“一对多|多对一”中,初学Hibernate的小伙伴可能在学习过程中会遇到这样的错误信息,然后我也遇到了
org.hibernate.TransientObjectException: object references an unsaved transient instance - save the transient instance before flushing: ...............
这个错误可能是由以下原因引起的:
1、save顺序不正确(百度得到的结果)
比如公司表和职员表,职员表存有公司的ID外键,是一对多的关系。在进行操作的时候应该是先执行公司表的save操作,再执行职员表的save操作。
2、在执行一对多的添加操作时,未对新增的对象的实行save操作。(自己在写demo的犯的错误)
最后祝大家早日处理好程序的异常。