0
votes

I was wondering if anyone has attempted and been successful at using the Morphia jar for interacting with a mongodb database inside of GWT? I've been using the below object as the base for all my POJO's, however whenever I attempt to save down the object using an UpdateOperations<DerivedPersistentEntity> or datastore.Save() I get a ConcurrentModificationException.

package com.greycells.dateone.shared;

import com.google.code.morphia.annotations.Id;
import com.google.code.morphia.annotations.Version;

public class PersistentEntity {

    @Id
    private String id;
    @Version
    private Long version = null;

    public PersistentEntity() {
    }

    public String getId() {
        return id;
    }

    public Long getVersion() {
        return version;
    }

    public void setVersion(Long version) {
        this.version = version;
    } 
}

I've also added the gwt extension jar that you have to download separately for Morphia and referenced it in my gwt.xml and this seems to be of no help. Additionally I've tried changing the id field of PersistentEntity to the ObjectId type but then I can't even get my project to bind correctly because it complains of...

[ERROR] No source code is available for type org.bson.types.ObjectId; did you forget to inherit a required module?

1
Do you try to call datastore.Save() directly from your GWT client code ? That's probably not going to work. you have to transmit the DTO to your backend and there you have to call datastore.save() - Ümit
No I only call the datastore.save from within the sever code, though it is a different servers than that which created the original DTO. But I do get the object again from the database before calling save. - hegsie

1 Answers

1
votes

You can't use a String for the @Id field of the entity in Morphia it must be an ObjectId. GWT support in Morphia is completely broken as of v1.02.