1
votes

I'm using Objectify 5.0.5, Objectify-GWT 1.2, GWT 2.6.1 and App Engine SDK 1.9.10.

I'm trying to do some very basic stuff with GAE, GWT and Objectify. I've done some things in GAE before and now I thought I should see if I can speed up production a bit by using Objectify but I'm climbing hurdle after hurdle. I'm not sure if I'm doing something wrong or if there's a bug in the library.

So here's my problem in general: I'm trying to use Ref.create(someEntity) on the client-side in GWT but it fails and prints:

Invalid type signature for com.googlecode.objectify.impl.ref.DeadRef

I've got the following entities/models:

@Entity
public class Persistable implements Serializable{
    private static final long serialVersionUID = 7733004846243513450L;

    @Id
    Long id;

    public Persistable() {}

    public void setId(Long id) {
        this.id = id;
    }
    public Long getId()
    {
        return id;
    }

    public void persist()
    {
        //This is actually a "remote service" and the only thing it does is call:
       //ofy().save().entity(entity);
        PPServices.getBasicService().persist(this, new AsyncCallback<Void>() {
           @Override
           public void onFailure(Throwable caught) {}
           @Override
           public void onSuccess(Void result) {}
        });
    }
}


@Subclass
public class Event extends Persistable{

    private static final long serialVersionUID = 1L;

    Ref<PPUser> host = null;

    public Event(){}


    public void setHost(PPUser participant)
    {
        host = Ref.create(participant);
    }
}

@Subclass
public class PPUser extends Persistable{

    private static final long serialVersionUID = 1L;

    public PPUser(){}

}

And I use them as following:

public class EntryStuff implements EntryPoint{

    public void onModuleLoad() {

        final Event event = new Event();
        final PPUser user1 = new PPUser();
        event.setHost(user1);

        event.persist();
    }

I can't see what's wrong. Even if I manually give user1 an ID it won't make any difference at all. Am I forced to set the host-field on the Server-side or what? In JDO I just create a new instance of PPUser and assign it and then persist/save the entity (in this case the Event) and it (PPUser) will be created, isn't the same possible here? :/

2

2 Answers

1
votes

UPDATE: Try with objectify-gwt-1.2.1; you still can't use Ref.create(POJO) client-side, but Ref<?>s should transit GWT-RPC correctly.


The GWT emulation for datastore classes that Objectify provides is slowly decaying.

Hi, I'm the principal author of Objectify. I used to work with GWT a lot, so I actively maintained the objectify-gwt code. However, it's now been multiple years since I last used GWT. In the mean time Objectify has changed, GWT has changed, and even the build systems have changed (objectify-gwt was split out into a separate jar because the old approach caused problems for Gradle users).

Something is broken in the emulation for some types (notably Ref and Key) under some specific circumstances. I do not understand the inner workings of GWT serialization well enough to fix it.

Objectify-gwt needs help from someone with a vested interest in making sure it works. Absent that, perhaps avoid trying to use Ref client-side?

0
votes

This "hack" solved my problem, I won't mark this as an answer though because this doesn't feel like a viable solution:

Add the following method to Persistable.java:

public Key<T> getKey() //Persistable is now actually Persistable<T>
{
    return Key.create(KeyFactory.createKey(getClass().getSimpleName(), id));
}

And in the Event.java:

public void setHost(PPUser host) {
    this.host = Ref.create(host.getKey());
}

Retarded solution since the docs states that I should be able to just pass the entire POJO-instance. In other words, instead of calling getKey() i should be able to just pass the object 'host' and it should work. This will work client-side, it will however NOT create the PPUser on the datastore, since it can't create a key on the client-side without an actual id (meaning, if the id is null you will get an exception).