Print Page | Close Window

ImportEntities and Temporary Id

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce 2010
Forum Discription: For .NET 4.0
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=3602
Printed Date: 13-May-2026 at 3:48am


Topic: ImportEntities and Temporary Id
Posted By: Walid
Subject: ImportEntities and Temporary Id
Date Posted: 31-Aug-2012 at 9:53am
Hi,

I have a question regarding the use of ImportEntites on an Entity having a temporary Id.
Here is the scenario :

- in the EM number 1 I create an entity. it gets the ID -100.
- in the EM number 2 (it was empty) I import this entity. it gets the ID -100 too
- I edit the entity in the EM2
- in the EM1 I import the entity from the EM2.

I was expecting the get the modification in the entity of the EM1. But instead I get 2 entity in the EM1, the unchanged original one and a new entity with the ID -101 having the modification.

I am aware of the Temporary Id remapping ( http://drc.ideablade.com/xwiki/bin/view/Documentation/entities-import - http://drc.ideablade.com/xwiki/bin/view/Documentation/entities-import ) but how can I import back an entity having a temporary ID ?


Below a project to reproduce my issue 
uploads/998/ImportAndTemporaryIds.rar - uploads/998/ImportAndTemporaryIds.rar



Replies:
Posted By: sbelini
Date Posted: 31-Aug-2012 at 12:13pm
Hi Walid,
 
This is the expected behavior.
Since both entities have temp Ids, we wouldn't be able to determine if they are the same or not.
 
Regards,
   Silvio.


Posted By: Walid
Date Posted: 31-Aug-2012 at 1:01pm
Thank for your response.
 
That's what I though but how can I achieve in such a scenario ?
 
actually I am about to keep trace of the dictionnary result of the 1st ImportEntities and after the 2nd ImportEntities (the import back) I will locate the originals entities and detach them from the entityManager.
I don't like much this solution but I don't see any other way to do it actually.
 


Posted By: sbelini
Date Posted: 31-Aug-2012 at 2:07pm
Walid,
 
Your idea might be a way to do it, although I don't think the temp Id values will be kept the same.
Before being persisted (i.e. having been assined a permanent Id) they basically are two different entities.
I would try assigning (i.e. copying) the values of Entity2 into Entity1 instead.
 
Regards,
   Silvio.


Posted By: mgood
Date Posted: 01-Sep-2012 at 12:16am
Walid,
It's not a good idea to import new entities with temporary ids. Once the entity gets saved by one EM it gets the permanent key assigned and now you are going to have to reconcile all copies in the various EMs with different temporary Ids. It's doable, but sure is a major pain.

DB generated Ids are a fundamental headache, because they violate one key principal of an entity and that is the identity of an entity should never change.

In rich client application's the best approach is to use Guids or a key generation service. Both have the same thing in common, the key is assigned by the client and doesn't change.

You will find that DB generated keys will make you jump through hoops in your client.



Print Page | Close Window