PersistentObjectException: detached entity passed to persist thrown by JPA and Hibernate

前端 未结 18 2345
醉酒成梦
醉酒成梦 2020-11-22 05:10

I have a JPA-persisted object model that contains a many-to-one relationship: an Account has many Transactions. A Transaction has one

18条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-22 05:50

    Probably in this case you obtained your account object using the merge logic, and persist is used to persist new objects and it will complain if the hierarchy is having an already persisted object. You should use saveOrUpdate in such cases, instead of persist.

提交回复
热议问题