今天使用Spring DataJPA保存数据时,出现以下错误:
Exception in thread “main” org.hibernate.TransientObjectException: object references an unsaved transient instance – save the transient instance before flushing: com.edurt.core
今天使用Spring DataJPA保存数据时,出现以下错误:
Exception in thread “main” org.hibernate.TransientObjectException: object references an unsaved transient instance – save the transient instance before flushing: com.edurt.core
这是因为你的对象引用了一个未保存的瞬态实例,换句话讲就是:因为主表的记录不曾插入,所以参照该记录的从表记录也就无法插入
通过
cascade=CascadeType.All
将Hibernate的所有持久化操作都级联到关联实体