org.hibernate.PersistentObjectException: detached entity passed to persist

后端 未结 7 1410
生来不讨喜
生来不讨喜 2020-11-30 00:56

I had successfully written my first master child example with hibernate. After few days I took it again and upgraded some libraries. No sure what did I do but I could never

7条回答
  •  误落风尘
    2020-11-30 01:40

    Two solutions 1. use merge if you want to update the object 2. use save if you want to just save new object (make sure identity is null to let hibernate or database generate it) 3. if you are using mapping like
    @OneToOne(fetch = FetchType.EAGER,cascade=CascadeType.ALL) @JoinColumn(name = "stock_id")

    Then use CascadeType.ALL to CascadeType.MERGE

    thanks Shahid Abbasi

提交回复
热议问题