Is it possible to detach Hibernate entity, so that changes to object are not automatically saved to database?

前端 未结 5 1237
野性不改
野性不改 2020-11-30 00:12

I have Hibernate entity that I have to convert to JSON, and I have to translate some values in entity, but when I translate values, these values are instantly saved to datab

5条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-30 00:49

    I am also converting hibernate entities to JSON.

    The bad thing when you close the session you cannot lazy load objects. For this reason you can use

    hSession.setDefaultReadOnly(true);
    

    and close the session after when you're done with the JSON.

提交回复
热议问题