简体   繁体   中英

Hibernate : merge an object detached from the session

I work on a client-server application that works like that :

1- the client calls the server to get a object from the DB

2- the server opens a hibernate session and get() an entity. Then closes the session.

3- in order to reduce the data transfered through the network, only a part of the data is copied into a Data Transfer Object.

4- the client updates the data, and send the Data Transfer Object back to the server.

5- the server converts the DTO to a new entity.

6- so the question is:

How to persist/merge the data from the client with the data from the database without overiding non-null values stored in the DB ?

Do I need to use update() ? merge() ? do I need to use the "dynamic-update=true" property ?

我认为唯一安全的策略是在步骤5中加载当前实体表单DB,然后将DTO复制到其中,然后再次保存。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM