document failed to save on update using 1.6.x #1867

Closed
yahonggu opened this Issue Dec 4, 2013 · 3 comments

2 participants

@yahonggu

we found that the odocument is not able to save during update, i.e. saving a new odocument works fine, when we update some fields and save the 2nd time, the changes are not persisted. The same code works fine on 1.4.1 and 1.5.0.

@lvca
OrientDB member

May you provide a piece of code? Otherwise we would need a witch to understand your problem! :-)

@lvca lvca was assigned Dec 4, 2013
@yahonggu

Sure, thanks for the quick response :), below is the relevant code:

/** We uses embedded database, and here is the method building storage configuration */
private OServerStorageConfiguration buildStorageConfiguration() {
OServerStorageConfiguration storage = new OServerStorageConfiguration();
storage.path = "local:" + settingsService.getOrientDbLocation();
storage.name = "odin";
storage.loadOnStartup = true;
storage.userName = settingsService.getOrientDbUsername();
storage.userPassword = settingsService.getOrientDbPassword();
return storage;
}

/** here is how we call the save using a callpack */

public <S extends T> S save(final S entity) {

    decorateWithIds(entity);

    ODocument document = orientDbTemplate.executeWithTx(new DocumentTxCallback<ODocument>() {


        @Override
        public ODocument withDocumentTx(ODatabaseDocumentTx documentTx) {

            OIdentifiable existing = findExisting(documentTx, entity.getId());

            ODocument document = null;

            if (existing != null) {

                document = existing.getRecord();
                T existingEntity = gson.get().fromJson(existing.getRecord().toJSON(), typeOfT);

                updateExistingWith(existingEntity, entity);
                document.fromJSON(gson.get().toJson(existingEntity));
                LOG.debug("Updating existing document with id " + entity.getId());
            } else {

                document = documentTx.newInstance();
                document.setClassName(typeName);
                document.fromJSON(gson.get().toJson(entity));
                LOG.debug("Creating new document with id " + entity.getId());
            }
            document = document.save(true);

            return document;
        }
    });

    final T savedEntity = gson.get().fromJson(document.toJSON(), typeOfT);
    return (S) savedEntity;

}

/** here is the orentDbTemplate call*/
public T executeWithTx(DocumentTxCallback callback) {

    ODatabaseDocumentTx documentTx = documentPool.acquire();

    try {

        documentTx.begin();
        T result = callback.withDocumentTx(documentTx);
        documentTx.commit();

        return result;
    } finally {
        documentTx.close();
    }

}
@lvca lvca modified the milestone: 2.0rc1, 2.1 Aug 28, 2014
@lvca
OrientDB member

Is this still valid?

@lvca lvca closed this Aug 28, 2014
@lvca lvca removed this from the 2.1 milestone Aug 28, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment