Hi,
I am developping an application that synchronized some documents (.doc, .xls,.pdf) from laptops to a server, I am using
Hibernate 1.2 to register the files on a SQLExpress, I make the files synchronization with an Ftp connection.
So when a user can register some files on the application on a disconnected mode, so the files are register on a directory (C:\Cleos\Data) and on a database. When the user wants to synchronized, the system verifires the status of all files in the database then throw those information on a remoting SQL Server then the files are sending to a remoting file server via the ftp connection.
Each document is an entity (DocumentNumerise) and the mapping follows :
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
namespace="Cleos2008.Domaine.Metier" assembly="Cleos2008.Domaine">
<class name="DocumentNumerise" table="documentNumerise" lazy="false" >
<id name="Id" column="documentNumerise_id" type="guid">
<generator class="guid" />
</id>
<property name="Ordre" column="ordre" type="integer" index="IDX_DocumentNumerise_Ordre"/>
<property name="Publication" column="publication" type="boolean"/>
<property name="Nom" column="nom" type="string" not-null="true" index="IDX_DocumentNumerise_Nom"/>
<property name="Commentaires" column="commentaires" type="string" length="1000"/>
<many-to-one name="Type" column="type" class="Cleos2008.Domaine.Aide.Referentiel" foreign-key="FK_DocumentNumerise_TypeDocument" index="IDX_DocumentNumerise_Type" />
<many-to-one name="Bien" column="bien_id" foreign-key="FK_Bien_DocumentNumerise" index="IDX_DocumentNumerise_Bien"/>
</class>
<query name="FindImages">
<![CDATA[from DocumentNumerise doc where doc.Bien = :bien and doc.Type.Libelle = 'Image' order by doc.Ordre ]]>
</query>
<query name="FindDocument">
<![CDATA[from DocumentNumerise doc where doc.Bien = :bien and doc.Type.Libelle <> 'Image' order by doc.Ordre ]]>
</query>
<query name="FindDocumentsTelechargesByUtilisateur" >
<![CDATA[select elements(util.DocumentTelecharge) from Utilisateur util where util = :utilisateur]]>
</query>
</hibernate-mapping>
When I register a file on the laptop I need to do a Save or a SaveOrUpdate to generate a new entity and genereate a new ID, but when I register the same document and if it does not exist on the server I only need to do a SaveOrUpdate and here begins the problem. In fact I can't UpDate because there is nothing to update on the server, no document exist with the actual ID and if I use the Save method this will generate an new entity with a new ID wich changes the identity of the object.
I need to keep the same ID on the laptop and on the server so the same entity, How can I resolved this problem without any hard modification?
Thx