2013-08-02 1 views
0

분리 상태의 영구 개체 변경과 관련된 문제가 발생했습니다. 이러한 변경은 서버의 일부 객체에 영향을 미치지 만 어떤 이유로 인해 DB의 객체 매핑에 영향을 미치지 않습니다.최대 절전 모드 : 변경 후 지속성 개체가 분리 상태 임

내가 무엇을 가지고 : 하나-2-많은 assosiation와 연결되어

두 기관 : 프로파일 -> 파일. 나는 새로운 파일을 추가하려고하는 파일 목록과 프로필을했습니다.

무슨 문제 :

내가 먼저 깨끗한 프로필의 파일 목록 (II-섹션) 그리고 나는 (III-섹션에서) 프로필에 새 파일을 추가 할 수 있습니다. 결국 DB에서 profile.getFileList()에 의해 제거 된 파일을 포함하여 모든 파일이 있습니다. clear();

질문 : 분명 내가 profile.getFileList을 (계속할 경우 결국 내가), DB 이전 파일에있는 이유는

().?

내 코드 :

//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 (프로필)를 호출 할 것이다. 세션 범위 밖으로 clear() 작업을 진행하려면 convertToJson (프로필)을 호출합니다. 사실, 그것은 내 클라이언트 - 서버 iteraction의 단순화 된 모델입니다. –

관련 문제