2013-08-02 45 views
0

我面臨與更改處於分離狀態的持久對象相關聯的問題。這些更改確實會影響服務器中的某個對象,但由於某些原因不會影響對象在數據庫中的映射。休眠:更改對象處於分離狀態後的持久性

我有什麼:

兩個實體與一個-2-許多assosiation鏈接:簡介 - >文件。我已經配置了文件列表,我嘗試添加新文件。

什麼問題:

我首先清潔配置文件的文件列表(在II段),然後我添加新的文件來分析(在三節)。畢竟,數據庫中的我擁有所有文件,包括被profile.getFileList()移除的文件。clear();

問:

爲什麼畢竟我在DB的舊文件,如果我繼續profile.getFileList()明確的()。?

我的代碼:

//I. pull the profile from BD 
Session session = sessionFactory.openSession(); 
Profile existingProfile = (Profile) session.get(Profile.class, profileId); 
session.close(); 

//II. make the copy of profile, out of the session scope, and clear file list of it 
String serializedProfile = convertToJson(profile); 
profile = Utils.jsonToObject(serializedProfile , Profile.class); 
profile.getFileList(); // not empty! 
profile.getFileList().clear(); 

//III. add new files to profile's file list 
Session session1 = sessionFactory.openSession(); 
session1.beginTransaction(); 
profiles.getFileList().addAll(additionalFileList); 
session1.saveOrUpdate(profile); 
session1.getTransaction().commit(); 
session1.close(); 

回答

1

舉行會議的範圍II段,爲什麼會做你清除文件清單

+0

沒有它不是之前所說的convertToJson(配置文件)。我調用convertToJson(配置文件)以進行清除()操作超出會話範圍。實際上,它是我的客戶端 - 服務器迭代的簡化模型。 –