New Posts New Posts RSS Feed: ImportEntities and Temporary Id
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

ImportEntities and Temporary Id

 Post Reply Post Reply
Author
Walid View Drop Down
Senior Member
Senior Member
Avatar

Joined: 14-Nov-2010
Posts: 161
Post Options Post Options   Quote Walid Quote  Post ReplyReply Direct Link To This Post Topic: ImportEntities and Temporary Id
    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) but how can I import back an entity having a temporary ID ?


Below a project to reproduce my issue 
Back to Top
sbelini View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 13-Aug-2010
Location: Oakland
Posts: 786
Post Options Post Options   Quote sbelini Quote  Post ReplyReply Direct Link To This Post 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.
Back to Top
Walid View Drop Down
Senior Member
Senior Member
Avatar

Joined: 14-Nov-2010
Posts: 161
Post Options Post Options   Quote Walid Quote  Post ReplyReply Direct Link To This Post 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.
 
Back to Top
sbelini View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 13-Aug-2010
Location: Oakland
Posts: 786
Post Options Post Options   Quote sbelini Quote  Post ReplyReply Direct Link To This Post 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.
Back to Top
mgood View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 18-Nov-2010
Location: Emeryville, CA
Posts: 583
Post Options Post Options   Quote mgood Quote  Post ReplyReply Direct Link To This Post 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.
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down