Salome HOME
Mapping is fixed. Relation in the mapping is inherited from Persistent now. Versionin...
[tools/siman.git] / Workspace / Siman-Common / src / org / splat / service / DocumentServiceImpl.java
index 325bfd19acec845fbcabae94ac1af47429629081..f7e811c7480ad516d317d67084f4c0262546737c 100644 (file)
@@ -34,6 +34,7 @@ import org.splat.dal.bo.som.Document.Properties;
 import org.splat.dal.dao.som.DocumentDAO;
 import org.splat.dal.dao.som.DocumentTypeDAO;
 import org.splat.dal.dao.som.FileDAO;
+import org.splat.dal.dao.som.StudyDAO;
 import org.splat.kernel.InvalidPropertyException;
 import org.splat.kernel.MissedPropertyException;
 import org.splat.kernel.NotApplicableException;
@@ -78,6 +79,10 @@ public class DocumentServiceImpl implements DocumentService {
         * Injected file DAO.
         */
        private FileDAO _fileDAO;
+       /**
+        * Injected study DAO.
+        */
+       private StudyDAO _studyDAO;
 
        /**
         * {@inheritDoc}
@@ -114,6 +119,9 @@ public class DocumentServiceImpl implements DocumentService {
                else
                        owner = ((Scenario) dprop.getOwner()).getOwnerStudy();
 
+               // Synchronize the object with the current Hibernate session.
+               owner = getStudyDAO().get(owner.getIndex());
+               
                SimpleDateFormat tostring = new SimpleDateFormat("yyyy");
                String year = tostring.format(owner.getDate());
                String filename = generateEncodedName(aDoc, owner);
@@ -449,7 +457,7 @@ public class DocumentServiceImpl implements DocumentService {
        public void release(Document aDoc) {
                aDoc.setCountag(aDoc.getCountag() - 1);
                if (aDoc.isSaved()) {
-                       getDocumentDAO().update(aDoc);
+                       getDocumentDAO().merge(aDoc);
                }
        }
 
@@ -527,7 +535,7 @@ public class DocumentServiceImpl implements DocumentService {
                // Update this document and the previous version, if exit
                if (previous != null) {
                        previous.setHistory(previous.getHistory() + 1);
-                       getDocumentDAO().update(previous);
+                       getDocumentDAO().merge(previous);
                }
                aDoc.setProgressState(state);
                getDocumentDAO().update(aDoc);
@@ -702,4 +710,20 @@ public class DocumentServiceImpl implements DocumentService {
                _fileDAO = fileDAO;
        }
 
+       /**
+        * Get the studyDAO.
+        * @return the studyDAO
+        */
+       public StudyDAO getStudyDAO() {
+               return _studyDAO;
+       }
+
+       /**
+        * Set the studyDAO.
+        * @param studyDAO the studyDAO to set
+        */
+       public void setStudyDAO(StudyDAO studyDAO) {
+               _studyDAO = studyDAO;
+       }
+
 }