object references unsaved transient instance

今天使用Spring DataJPA保存数据时,出现以下错误:

Exception in thread “main” org.hibernate.TransientObjectException: object references an unsaved transient instance – save the transient instance before flushing: com.edurt.core
阅读 2.2k
1 个回答

这是因为你的对象引用了一个未保存的瞬态实例,换句话讲就是:因为主表的记录不曾插入,所以参照该记录的从表记录也就无法插入

通过cascade=CascadeType.All将Hibernate的所有持久化操作都级联到关联实体

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进