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

前端 未结 5 1236
野性不改
野性不改 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条回答
  •  猫巷女王i
    2020-11-30 00:50

    You can detach an entity by calling Session.evict().

    Other options are create a defensive copy of your entity before translation of values, or use a DTO instead of the entity in that code. I think these options are more elegant since they don't couple conversion to JSON and persistence layer.

提交回复
热议问题