Error: detached entity passed to persist - try to persist complex data (Play-Framework)

后端 未结 4 1754
无人共我
无人共我 2021-02-04 12:57

I have a problem with persisting data via play-framework. Maybe it\'s not possible to achive that result, but it would be really nice if it would work.

Simple

4条回答
  •  野的像风
    2021-02-04 13:37

    When you update a complex instance in Hibernate you need to make sure it is coming from the database (fetch it first, then update that same instance) to avoid this 'detached instance' problem.

    I generally prefer to always fetch first and then only update specific fields I'm expecting from the UI.

    You can make your code a bit more generic using

    (T)Model.Manager.factoryFor(relation.getClass()).findById(relation.id);
    

提交回复
热议问题