Hey, Unless I'm doing something horribly wrong the ID in that object isn't being updated. That's what I thought at the beginning but if I call getIdentity() after commit() I still am getting the temporary ID instead of the proper one. I'll go through the code, both my code and Orient's, to see where's the problem and if it indeed should work as you say.
Mateusz On 28 March 2014 22:49, Odysseas Pentakalos <[email protected]> wrote: > Mateusz, > > I haven't tested this on a remote connection but on a local connection the > ID of your object will be updated by reference once the commit is done so > you don't need to perform another query. So, in the example you have shown > above, if you do make a call to saved.getIdentity() before the commit you > will get a temporary ID but if you call saved.getIdentity() after the > commit, you should get a permanent one. Perhaps I am misunderstanding your > question? > > Odysseas > > > > > On Thu, Mar 27, 2014 at 8:13 PM, Mateusz Dymczyk <[email protected]> wrote: >> >> Odysseas, >> >> Yes I'm aware of that. The thing is it requires an additional request to >> the DB (yes not much overhead but I don't like it), me writing a method >> looking for an identical record (except the ID) which will have to be very >> generic AND potential problems if someone by mistake adds a DB class which >> doesn't have to be unique, in such case I won't have any way of telling >> which record's ID should I retrieve as there could be multiple identical >> ones. In such case I would have to add some kind of a timestamp or my my own >> ID. >> >> I was wondering if there's a way to retrieve the result of the commit >> (what the commit actually did, some kind of temp -> permanent ID mapping) or >> to reload the document we got back from save() so it updates it's ID >> automatically. >> >> Mateusz >> >> >> On Thursday, March 27, 2014 11:27:02 PM UTC+9, Odysseas wrote: >>> >>> Mateusz, >>> >>> After the commit the object will have a permanent ID assigned to it so if >>> you retrieve the identity of the saved object, you should get a permanent >>> record ID. >>> >>> Odysseas >>> >>> On Wednesday, March 26, 2014 11:16:43 AM UTC-4, Mateusz Dymczyk wrote: >>>> >>>> As mentioned in the wiki >>>> (https://github.com/orientechnologies/orientdb/wiki/Transactions) while >>>> storing documents in the DB in a transaction they are assigned a temporary >>>> ID. Is there any way to get the permanent ID of that record after a commit? >>>> I read in one of the discussions that the commit() should return a mapping >>>> of changed IDs but I couldn't find is it how it actually works/how to use >>>> it. >>>> >>>> Let's say we have a sample code like in the wiki example: >>>> >>>> try{ >>>> db.begin(TXTYPE.OPTIMISTIC); >>>> ODocument saved = db.save(document); >>>> db.commit(); >>>> return saved; >>>> } catch( Exception e ){ >>>> db.rollback(); >>>> } finally{ >>>> db.close(); >>>> } >>>> >>>> Is there a way to store in "saved" the permanent ID instead of the >>>> temporary one before the return statement? A query for that permanent ID >>>> would be one way but I would really prefer to avoid having to do that kind >>>> of "tricks". >>>> >>>> Regards, >>>> Mateusz >> >> -- >> >> --- >> You received this message because you are subscribed to a topic in the >> Google Groups "OrientDB" group. >> To unsubscribe from this topic, visit >> https://groups.google.com/d/topic/orient-database/slAw072CzvE/unsubscribe. >> To unsubscribe from this group and all its topics, send an email to >> [email protected]. >> For more options, visit https://groups.google.com/d/optout. > > > -- > > --- > You received this message because you are subscribed to a topic in the > Google Groups "OrientDB" group. > To unsubscribe from this topic, visit > https://groups.google.com/d/topic/orient-database/slAw072CzvE/unsubscribe. > To unsubscribe from this group and all its topics, send an email to > [email protected]. > For more options, visit https://groups.google.com/d/optout. -- --- You received this message because you are subscribed to the Google Groups "OrientDB" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.
